Page 1 of 1

Extract image from PSD file

Posted: 2017-12-12T22:10:53-07:00
by johnbasi
Hi, sorry for asking this question but I'm a newbie on IM.

I have images with different backgrounds and I want to extract the image out and create a new file. Please take note that the images has alpha channels.

Here is the file: ... 1.psd?dl=0

IM version: ImageMagick 7.0.1-3 Q16 x64 2016-05-11
OS: Windows

Re: Extract image from PSD file

Posted: 2017-12-12T23:13:51-07:00
by fmw42
You asked this question on the Developer's forum and got several answers. see viewtopic.php?f=2&t=33202

If you are asking a different question, please clarify your question with more details about your command line that you have tried and what you expect for the result (or an example input and output).

Re: Extract image from PSD file

Posted: 2017-12-12T23:55:58-07:00
by johnbasi
I am asking a different question. I want to extract the image out of the file. I have steps on how to do it in Photoshop but I want to convert it to IM command. I am new to IM so I don't have an idea how to make those commands.

Here is the steps on PS:
1. Select channel(Alpha 1)
2. Set Selection
3. Inverse
4. Select RGB channel
5. Delete

It will remove the background and retain the image but I don't know how to convert these steps to IM command.

Re: Extract image from PSD file

Posted: 2017-12-13T00:28:38-07:00
by fmw42
As was said before in the previous post, IM sees your PSD file as having a fully opaque alpha channel (alpha). It does not recognize the extra alpha 1 channel. So taking the first layer and processing it as follows, I can extract the alpha channel by making everything that is near the blue color transparent.

Code: Select all

convert 44-2868_11.psd[0] -fuzz 10% -transparent "#4CDEFE" -alpha extract alpha.png
Please note that ImageMagick has limited Photoshop PSD file processing capabilities.

Re: Extract image from PSD file

Posted: 2017-12-13T00:34:26-07:00
by johnbasi
Hi, thanks for your quick response.

The "blue" background is just one of the images and there are lots of other images with different backgrounds. Is there any way not to specify the image color to be replaced?

I got this error on my end when running the command:
convert: profile 'icc': 'RGB ': RGB color space not permitted on grayscale PNG `alpha.png' @ warning/png.c/MagickPNGWarningHandler/1683.

Re: Extract image from PSD file

Posted: 2017-12-13T00:38:43-07:00
by fmw42
That message is to be expected, since PNG does not allow a grayscale image to have an RGB colorspace. It is just a warning.

Since your image has extra alpha channels, IM cannot see them and must do it vs color. If you have other PSD files with just one not fully opaque alpha channel, then IM should be able to extract that directly.

Re: Extract image from PSD file

Posted: 2017-12-13T00:44:35-07:00
by johnbasi
Yes, I saw the output and it extracted the alpha channel but what I want is to extract the main image using that alpha channel.

I have added a link for the desired output. I was able to do it in PS but I want IM since there are lots of images to process. ... t.PNG?dl=0

Re: Extract image from PSD file

Posted: 2017-12-13T00:48:17-07:00
by fmw42
I posted that solution in the other post of yours. See viewtopic.php?f=2&t=33202#p152099

Code: Select all

convert 44-2868_11.psd[0] -fuzz 10% -transparent "#4CDEFE" result.psd
That is the only way to do it in ImageMagick, since your image has an "alpha" channel that is fully opaque and a separate alpha1 channel that IM does not recognize at this time.

You can output to PNG if you want rather than PSD.