batch remove one layer of psd

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
matroosje
Posts: 3
Joined: 2017-02-21T01:18:36-07:00
Authentication code: 1151

batch remove one layer of psd

Post by matroosje »

Hi,
I have some psd images that I would like to flatten and convert to png while removing a layer. The layer that I would like to remove is a paspartout (the layer is also called paspartout). I know how to flatten and convert. I use

Code: Select all

mogrify -format png *.psd[0]
I could of course open the files one by one and remove the paspartout, but I have hundreds of files that I would like to process that way.

So is there a way to exclude a layer while flattening an image?

I use ubuntu 16.04 and a terminal
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: batch remove one layer of psd

Post by snibgo »

So, you want to flatten all the layers apart from one? So, read all the layers, delete the one you don't want, and flatten:

Code: Select all

convert in.psd -delete 4 out.png
Then you can put that in a shell loop to process all the files.

I don't know how to get layer names from PSD files.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: batch remove one layer of psd

Post by fmw42 »

IM does not know about layer names.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: batch remove one layer of psd

Post by snibgo »

I don't use Photoshop, but judging from some PSD samples shown in these forums, the "label" property might be the Photoshop layer name.
snibgo's IM pages: im.snibgo.com
matroosje
Posts: 3
Joined: 2017-02-21T01:18:36-07:00
Authentication code: 1151

Re: batch remove one layer of psd

Post by matroosje »

Hi everybody,
I tried using -delete, but it only works with numbers I think, not with a layer that has a name 'paspartout'. (It's the last layer that has been added, so sometimes it's the 6th, sometimes the 13th.)

Is there a way rename a layer? If I could rename 'paspartout' to a number, say 99, I could afterwards remove layer 99 out of all the images with -delete and flatten them. That would be nice.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: batch remove one layer of psd

Post by snibgo »

matroosje wrote:(It's the last layer that has been added, so sometimes it's the 6th, sometimes the 13th.)
So, does "+delete" do what you need?
snibgo's IM pages: im.snibgo.com
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: batch remove one layer of psd

Post by GeeMack »

matroosje wrote: 2017-02-22T07:42:32-07:00I tried using -delete, but it only works with numbers I think, not with a layer that has a name 'paspartout'. (It's the last layer that has been added, so sometimes it's the 6th, sometimes the 13th.)
You shouldn't have to know any layer names. As long as you're certain the layer you want to eliminate is the last in every case, "convert" or "mogrify" should be able to handle it easily. I've tried using "+delete", as snibgo mentioned above, and "-delete -1" to delete the last layer after the PSD is read in. Both seem to work. Something like this should do it...

Code: Select all

mogrify -delete -1 -format png *.psd
I've also tried reading in the PSD file all except the last layer. That's done by including the index or range of indexes of the layers you want in square brackets appended to the input file name. The command would look like this...

Code: Select all

mogrify -format png *.psd[0--2]
Those commands work for me from a Windows x64 command prompt using either IM 6.9.7 or IM 7.0.5 to test some PhotoShop Elements and PhotoShop CS2 files.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: batch remove one layer of psd

Post by fmw42 »

+delete is the same as -delete -1 Both delete the last image in the sequence.
matroosje
Posts: 3
Joined: 2017-02-21T01:18:36-07:00
Authentication code: 1151

Re: batch remove one layer of psd

Post by matroosje »

Thanks,
That indeed does work, combined with -flatten, I get what I want

Code: Select all

mogrify -delete -1 -flatten -format png *.psd
Thanks again!
Post Reply