Page 1 of 1

batch remove one layer of psd

Posted: 2017-02-21T01:31:28-07:00
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

Re: batch remove one layer of psd

Posted: 2017-02-21T08:17:47-07:00
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.

Re: batch remove one layer of psd

Posted: 2017-02-21T10:38:05-07:00
by fmw42
IM does not know about layer names.

Re: batch remove one layer of psd

Posted: 2017-02-21T10:48:06-07:00
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.

Re: batch remove one layer of psd

Posted: 2017-02-22T07:42:32-07:00
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.

Re: batch remove one layer of psd

Posted: 2017-02-22T07:46:10-07:00
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?

Re: batch remove one layer of psd

Posted: 2017-02-22T17:37:12-07:00
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.

Re: batch remove one layer of psd

Posted: 2017-02-22T19:35:28-07:00
by fmw42
+delete is the same as -delete -1 Both delete the last image in the sequence.

Re: batch remove one layer of psd

Posted: 2017-02-23T04:30:48-07:00
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!