Page 1 of 1

PSD to PNG advice...

Posted: 2010-07-02T10:21:16-07:00
by ian313665
I'm using ImageMagick to convert a PSD to a PNG file and I have a few questions.

If I execute this command:

Code: Select all

convert test.psd out.png
I get an output of two images. (See links for source and output files)

I'm assuming the reason two files are produced is something to do with the layers within the PSD file? If I open the PSD in Photoshop, I can only see 1 layer. Also, if you inspect the two output files closely, you will notice index 0 seems to have a white/grey fringe within the feathered edge and index 1 is a perfect conversion.

I experimented with this command:

Code: Select all

convert test.psd[1] out.png
... and achieved the result I want. I'm still confused as to why I need to use an index of 1 as the file displays one layer. Secondly, why is there a white/grey fringe added to index 0?

Finally, how can I modify my approach to assure I get the correct PSD -> PNG conversion and not rely on layers. Some of the files I process may not have an index 0? .... or can I assume index 1 will always be there?

Any help is much appreciated, thank-you in advance.

Re: PSD to PNG advice...

Posted: 2010-07-02T11:02:02-07:00
by fmw42
Usually (and perhaps always), image.psd[0] is the flattened layer of all the other layers. so if you have only one layer, you may get [0] and [1]. Layer [0] may be layer [1] flattened against a background color.

Your two results -0 and -1 are offset as well and -1 is smaller than -0. So you have a partial layer/frame for -1.

Perhaps this is some strange malformed PSD file that does not conform to usual standards. How was it created?

If you do

convert test.psd -coalesce testpsd2_%d.png

then the two frames are the same size and properly centered and only differ by the feathering.

I don't believe that IM can handle all possible PSD layer types. So perhaps layer 0 has all of them flattened together and layer 1 is only the base layer before some other layers are applied that IM cannot extract. Other PSD experts can correct me if I am wrong.

Re: PSD to PNG advice...

Posted: 2010-07-02T11:59:58-07:00
by ian313665
fmw42 wrote:How was it created?
The PSD was created in Photoshop. It's just a cropped corner of a larger image for demonstration purpose.

The only thing I can think of about the dimension mismatch is a similarity with Photoshop itself. If you 'select all' on a layer that only has pixels in the centre and not to the edges, then copy and paste it. Photoshop only pastes the actual pixels and ignores the alpha parts. Another words, selecting all on this 28x28 test image, copying it and pasting it to a new layer would only paste 24x24 image centred (ie. you see the 2 pixel offset)

I do have an alternative to get around the fringing problem and that is to not use ImageMagick for the conversion and do it all manually. It's no big problem. I don't know enough about ImageMagick however to detect if the fringing is normal behaviour.

I've also tried this but the feathered edges still have a white/grey tint:

Code: Select all

convert test.psd -background none -flatten out.png

Re: PSD to PNG advice...

Posted: 2010-07-02T12:05:52-07:00
by fmw42
The real question is are the fringes real and from photoshop. I believe that it is real and coming from an alpha channel to fade the edges.

So I would ask again. What steps did you use to create the image from which you cropped the corner? Did it include an alpha channel to fade the edges? What does the original large image from which you cropped the corner look like?

It seems like you have two frames/layers. One has a nearly binary alpha and the other has a ramped or feathered alpha. Do

identify -verbose test.psd

you will see two sets of data. You can see the differences in the alpha channel from the two histograms.

For some reason, this PSD image does not seem to have flattened the layers into layer [0] as is usual.