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

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
MikeOwen
Posts: 7
Joined: 2011-05-18T10:32:32-07:00
Authentication code: 8675308

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

Post 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
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

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

Post 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!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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.
MikeOwen
Posts: 7
Joined: 2011-05-18T10:32:32-07:00
Authentication code: 8675308

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

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

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

Post by Bonzo »

The image link points to a png image unless I am doing something wrong.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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.
MikeOwen
Posts: 7
Joined: 2011-05-18T10:32:32-07:00
Authentication code: 8675308

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

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post by fmw42 »

Your download page does not seem to work for me.
MikeOwen
Posts: 7
Joined: 2011-05-18T10:32:32-07:00
Authentication code: 8675308

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

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

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

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply