PSD to png - black background

Magick.NET is an object-oriented C# interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick.NET
lucd
Posts: 22
Joined: 2018-09-11T14:50:41-07:00
Authentication code: 1152

Re: PSD to png - black background

Post by lucd »

snibgo wrote:
2020-05-09T19:37:01-07:00
That tif file contains two images, with different sizes. Only the second image has an alpha channel.

Please show your complete code. Perhaps you are reading both images, and flattening them together.
thanks snibgo
i use the same code posted above

Code: Select all

magickImageCollection = new MagickImageCollection(content, settings);
image = magickImageCollection.Flatten(new MagickColor(MagickColors.Transparent));
the collection has only one image once loaded from content, before flattening.
this image does not have alpha but a clipping
after flattening, of course one single image too with an alpha later and a clipping

in photoshop, there is one single layer too
how do you see mulitple images ? and how would you know which one to keep (with the transparency) ?
thanks
Last edited by lucd on 2020-05-10T03:28:55-07:00, edited 3 times in total.

lucd
Posts: 22
Joined: 2018-09-11T14:50:41-07:00
Authentication code: 1152

Re: PSD to png - black background

Post by lucd »

fmw42 wrote:
2020-05-09T19:37:19-07:00
The transparency is coming from a clip path. Here is how to handle that in command line. Sorry, I do not know Magick.Net

Code: Select all

convert -quiet tif1.tif[0] -alpha transparent -clip -alpha opaque -strip tif1.png
Thanks fmw42, gonna try to find the equivalent.
what properties on the image should i check to know i need to apply this method instead ?
mosts psds or tiff i process have a clipping path in the source, while psd are processed corrrectly,
so i don't know how i could identify them to apply a different threatment

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: PSD to png - black background

Post by snibgo »

You have not shown your complete code. Do you read one image or the entire tiff file, which is two images? The code you show doesn't write any files.
snibgo's IM pages: im.snibgo.com

lucd
Posts: 22
Joined: 2018-09-11T14:50:41-07:00
Authentication code: 1152

Re: PSD to png - black background

Post by lucd »

Snibgo ,

I cannot post the complete code, it is part of a project


Still, that was it :)
i was reading only the first frame in the collection using

Code: Select all

                MagickReadSettings settings = new MagickReadSettings
                {
                    FrameIndex = 0,
                     Density = new Density(300, 300, DensityUnit.PixelsPerInch)
                };

Now i read all the frames, then i select the one with alpha (if any)

Code: Select all

                        // if multiple images in collection take the one with alpha layer
                        if (magickImageCollection.Count > 1) {
                            image = magickImageCollection.FirstOrDefault(x => x.HasAlpha);
                        }
                        // in case we didn't have a frame with alpha
                        if (image == null)
                            image = magickImageCollection.Flatten(new MagickColor(MagickColors.Transparent));
                            
                            
And here is the transparency !!

Thanks a lot !!

Locked