Extract image from PSD file

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
johnbasi
Posts: 14
Joined: 2017-12-08T02:45:45-07:00
Authentication code: 1152

Extract image from PSD file

Post 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:
https://www.dropbox.com/s/hoj6pwvnomleh ... 1.psd?dl=0

IM version: ImageMagick 7.0.1-3 Q16 x64 2016-05-11
OS: Windows
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Extract image from PSD file

Post 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).
johnbasi
Posts: 14
Joined: 2017-12-08T02:45:45-07:00
Authentication code: 1152

Re: Extract image from PSD file

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

Re: Extract image from PSD file

Post 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.
johnbasi
Posts: 14
Joined: 2017-12-08T02:45:45-07:00
Authentication code: 1152

Re: Extract image from PSD file

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

Re: Extract image from PSD file

Post 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.
johnbasi
Posts: 14
Joined: 2017-12-08T02:45:45-07:00
Authentication code: 1152

Re: Extract image from PSD file

Post 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.

https://www.dropbox.com/s/lnbuqlw504j0f ... t.PNG?dl=0
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Extract image from PSD file

Post 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.
Post Reply