Page 1 of 1

Convert PSD layer to PNG - keep layer[0] size

Posted: 2011-05-18T10:49:18-07:00
by MikeOwen
Hi,
Using Windows, [Version: ImageMagick 6.6.9-7 2011-04-29 Q16 http://www.imagemagick.org], "convert.exe" to export a Photoshop PSD layer to PNG BUT I need it to keep its original Master Photoshop canvas size.
So far, I know I can calculate the original Photoshop canvas size by doing this:

Code: Select all

"C:\identify.exe" -format "%w x %h" c:\mike.psd"[0]
which gives a result of:

Code: Select all

8000 x 6000
and then I can do something like:

Code: Select all

"C:\convert.exe" "c:\mike.psd"[1] "c:\mike.png"
However, the file created "mike.png" is a trimmed size and not at the size "8000 x 6000".

I'm struggling to find the correct syntax to force the non-trimming of the output png file. I also need the PNG files to be correct "alphed out" as they are in the PSD file.

I tried this:

Code: Select all

-layers TrimBounds
but it does not work!

Does anyone know the correct method / syntax? I would love to know!

Thanks,
Mike

Re: Convert PSD layer to PNG - keep layer[0] size

Posted: 2011-05-18T11:04:03-07:00
by Bonzo
A lot of people here either do not use photoshop or do not have access to it; a demo file would be helpful although a 8000 x 6000 file might be a bit large!

Re: Convert PSD layer to PNG - keep layer[0] size

Posted: 2011-05-18T11:22:38-07:00
by fmw42
However, the file created "mike.png" is a trimmed size and not at the size "8000 x 6000".
The layer [1] you used may be an update layer and not full size. In general the first layer [0] is the flattened, full size psd image. So perhaps try with layer [0]. Otherwise, I am not sure but -coalesce may help, though I don't know if it only works for gif multiframe (animations)

You can try (though I have no idea if this is reasonable):

convert mike.psd[1] -coalesce mike.png

Also you can see if the pds layer has a virtual canvas from identify -verbose mike.psd[1] (see Page geometry: ) If the size is your original size and there is an offset, you can try flattening the result against some background color.

convert mike.psd[1] -background white -flatten mike.png

Let us know if any of this helps.

Re: Convert PSD layer to PNG - keep layer[0] size

Posted: 2011-05-18T13:13:46-07:00
by MikeOwen
Hi,
See example Photoshop CS5 PSD file.

https://docs.google.com/viewer?a=v&pid= ... y=CJWJp4UO

Unfortunately, none of your suggestions have resolved the issue.
The page geometry displays the correct image size of "800x600" (I down-sized from 8000 x 6000 for the purposes of this example).
However, when you execute the following:

Code: Select all

"C:\ImageMagick-6.6.9-7\convert.exe" "c:\mike.psd"[1] -background white -flatten "c:\mike.png"
or

Code: Select all

"C:\ImageMagick-6.6.9-7\convert.exe" "c:\mike.psd"[1] -coalesce "c:\mike.png"
A PNG file is created with dimensions: 674 x 365 when I need it to be 800 x 600.

I think the only option is to dynamically create a transparent PNG background and composite the PSD[layer] onto this PNG file and overwrite it.

Any ideas on how to achieve this / the syntax for this operation?

Thanks,
Mike

Re: Convert PSD layer to PNG - keep layer[0] size

Posted: 2011-05-18T13:24:19-07:00
by fmw42
can you provide a link to your 800x600 psd file? otherwise, try

convert -size 800x600 xc:none mike.psd[1] -gravity center -composite PNG32:mike.png

or

convert mike.psd[1] -gravity center -background none -extent 800x600 PNG32:mike.png

Re: Convert PSD layer to PNG - keep layer[0] size

Posted: 2011-05-18T13:46:17-07:00
by Bonzo
The image link points to a png image unless I am doing something wrong.

Re: Convert PSD layer to PNG - keep layer[0] size

Posted: 2011-05-18T13:56:30-07:00
by fmw42
Bonzo wrote:The image link points to a png image unless I am doing something wrong.
Yes, that is what I found and why I asked him to post a link to his psd file.

Re: Convert PSD layer to PNG - keep layer[0] size

Posted: 2011-05-18T15:30:55-07:00
by MikeOwen
Sorry about that guys. Looks like google docs auto converts the files, even if you tell it not too!
See here for zipped PSD file:

https://docs.google.com/leaf?id=0B_ZIMD ... y=COON6_MC

I tried the provided commands and they both seem to have worked. I will have to look into the exact syntax and what it means tomorrow.
I'll have to look into which method is the best way to go and why.

Thanks for your help,
Mike

Re: Convert PSD layer to PNG - keep layer[0] size

Posted: 2011-05-18T17:04:51-07:00
by fmw42
Your download page does not seem to work for me.

Re: Convert PSD layer to PNG - keep layer[0] size

Posted: 2011-05-18T23:44:37-07:00
by MikeOwen
Strange it seems to be working:

Code: Select all

https://docs.google.com/leaf?id=0B_ZIMDeFwyzQYWUyMTRkNzAtMTFmZi00M2NkLTk0OTAtZTViYTViOTc2ZTk0&sort=name&layout=list&num=50

Re: Convert PSD layer to PNG - keep layer[0] size

Posted: 2011-05-19T09:43:03-07:00
by fmw42
got it today - don't know what happened yesterday.

identify mike.psd
mike.psd[0] PSD 800x600 800x600+0+0 8-bit DirectClass 455KB 0.140u 0:00.369
mike.psd[1] PSD 674x365 674x365+40+141 8-bit DirectClass 455KB 0.120u 0:00.289
mike.psd[2] PSD 624x439 624x439+72+52 8-bit DirectClass 455KB 0.120u 0:00.289
mike.psd[3] PSD 526x453 526x453+135+88 8-bit DirectClass 455KB 0.110u 0:00.279

I am not sure but perhaps the offset +40+141 might place frame [1] relative to the 800x600 background

This seems to work and the blue line is in the right place compared with the original image. So it is getting the virtual canvas offset correctly from the image information:

convert -size 800x600 xc:none -background none mike.psd[1] -flatten PNG32:mike_tmp2.png

Re: Convert PSD layer to PNG - keep layer[0] size

Posted: 2011-05-19T17:22:54-07:00
by anthony
In this case the canvas size of the second (index=1) image is not correct.
It looks like IM may only be making a guess at a value that is not supplied
and getting it wrong, the better canvas size is either size + offset

Note however that the canvas size is often not critical, and resetting it to zero -repage 0x0 will get IM to re-calculate the canvas (to fit image) when it requires one.

Flatten which was designed with PSD images in mind, only uses the canvas size of the first image, and the offsets of all the images for its processing.