Page 1 of 1

[SOLVED] Extract layers from PSD and merge together

Posted: 2018-08-08T08:05:30-07:00
by zappzerapp
Hi community,

I want to extract layers from the test.psd and merge them with the same result together again.

To get the layers I have done the following:

Code: Select all

identify -verbose -format "label:%l,geometry:%g\n" test.psd
Output:

Code: Select all

label:,geometry:1000x1000+0+0
label:eins,geometry:233x318+54+58
label:zwei,geometry:413x412+585+80
To extract them:

Code: Select all

convert test.psd[1] -page +0+0 test1.psd
convert test.psd[2] -page +0+0 test2.psd
And now I want to put the whole thing back together, but i just don't get it.
So how can I create the test.psd if I only would have test1.psd and test1.psd and the information from the first command ( So that the picture has a size of 1000x1000 and how the two levels are positioned )

Many thanks for your help!


Resources:
http://buzzram.de/img/uploads/test.psd
http://buzzram.de/img/uploads/test1.psd
http://buzzram.de/img/uploads/test2.psd

Re: Extract layers from PSD and merge together

Posted: 2018-08-08T09:21:10-07:00
by fmw42
PSD files have a hidden flattened layer that is layer 0. When I convert your PSD to PNG, I get 3 PNG images. You just need to read those back to recreate your PSD file, including the flattened layer as the first (layer 0)

Code: Select all

identify test.psd
test.psd[0] PSD 1000x1000 1000x1000+0+0 8-bit CMYK 1.03282MiB 0.010u 0:00.000
test.psd[1] PSD 233x318 233x318+54+58 8-bit CMYK 1.03282MiB 0.010u 0:00.000
test.psd[2] PSD 413x412 413x412+585+80 8-bit CMYK 1.03282MiB 0.010u 0:00.000

Code: Select all

convert test.psd test_%d.png
Image
Image
Image

Code: Select all

convert test_*.png test2.psd

Code: Select all

identify test2.psd
test2.psd[0] PSD 1000x1000 1000x1000+0+0 8-bit sRGB 357734B 0.010u 0:00.000
test2.psd[1] PSD 233x318 233x318+54+58 8-bit sRGB 357734B 0.000u 0:00.000
test2.psd[2] PSD 413x412 413x412+585+80 8-bit sRGB 357734B 0.000u 0:00.000

You can also do it by saving to TIFF or PSD in place of PNG, but you have to force the layers to be separated into individual images using +adjoin

Code: Select all

convert test.psd +adjoin test_%d.psd
convert test_*.psd test2.psd

Re: Extract layers from PSD and merge together

Posted: 2018-08-09T02:41:00-07:00
by zappzerapp
Hi Fred,

thanks for your reply!

When I convert the PSD to 3 PNGs and merge them together, the result looks nearly like I wanted to do. (I am amazed that even the layer names are not lost)
Unfortunately, I can not use the solution, because it loses the color space and the color profile.

I also tried the variant with +adjoin but the problem here is the following:

Code: Select all

identify -verbose -format "label:%l,geometry:%g\n" test_0.psd
label:,geometry:1000x1000+0+0
label:eins,geometry:233x318+54+58
label:zwei,geometry:413x412+585+80
- everything looks fine

Code: Select all

identify -verbose -format "label:%l,geometry:%g\n" test_1.psd
label:,geometry:233x318+0+0
label:zwei,geometry:413x412+585+80
- label and content should be "eins"

Code: Select all

identify -verbose -format "label:%l,geometry:%g\n" test_2.psd
label:,geometry:413x412+0+0
label:zwei,geometry:413x412+585+80
- everything looks fine

Code: Select all

identify -verbose -format "label:%l,geometry:%g\n" test2.psd
label:,geometry:1000x1000+0+0
label:eins,geometry:233x318+54+58
label:zwei,geometry:413x412+585+80
label:L3,geometry:233x318+0+0
label:zwei,geometry:413x412+585+80
label:L5,geometry:413x412+0+0
label:zwei,geometry:413x412+585+80
- totally messed up, but if I'd only left a single "eins"-Layer and a single "eins"-layer, the picture would be fine

Re: Extract layers from PSD and merge together

Posted: 2018-08-09T08:56:47-07:00
by fmw42
I think my command works to keep CMYK and your profile, if you use tiff rather than png. PNG does not support CMYK, but TIFF does. If your profile is lost, then you can easily add it back again when recreating the PSD from the individual TIFFs.

Re: Extract layers from PSD and merge together

Posted: 2018-08-10T08:32:07-07:00
by zappzerapp
TIFF is the solution.

Many Thanks!