Page 1 of 1

export levels' psd

Posted: 2014-08-23T11:28:53-07:00
by iacoposk8
I would like to create a script in php (or another language) that exports all layers of a psd file. I wrote:

Code: Select all

<?php
    $im = new Imagick("Senza titolo-1.psd");
    for ($i = 0, $num_layers = $im->getNumberImages(); $i < $num_layers; ++$i) {
        $im->writeImage('layer_' . $i . '.png');
    }


    $im->flattenImages();
    $im->setImageFormat('png');
    $im->writeImage('test.png');
?>
the first half of code, export layers, the second half layers merged. if we do the test with this file:
https://drive.google.com/file/d/0Bzaq0S ... sp=sharing

I see that exports 3 black arrows while the psd contains a single blue arrow. how do I fix it?

ps: I'm okay with any method, even without Imagick

Re: export levels' psd

Posted: 2014-08-23T11:57:27-07:00
by dlemstra
Why do you want to merge the layers yourself? The first image is the combined image. You can read it like this:

Code: Select all

$im = new Imagick("Senza titolo-1.psd[0]");

Re: export levels' psd

Posted: 2014-08-23T23:03:54-07:00
by iacoposk8
I tried, but the exported image is not only the blue arrow, but the arrow blue with a white background. I would like to have only the arrow cropped with transparent background.

Re: export levels' psd

Posted: 2014-08-24T10:55:36-07:00
by fmw42
You have no one layer that is what you want. You will need to combine layers with some code to get it. This should do it.

Unix syntax:

Code: Select all

convert Senza_titolo-1.psd[0] \
\( +clone -fill black -colorize 100 -alpha transparent \) \
\( Senza_titolo-1.psd[2] -negate -alpha extract \) \
\( -clone 1 -clone 2 -background none -flatten -alpha off \) \
-delete 1,2 \
-compose over -compose copy_opacity -composite result.png
For Windows, see syntax changes at http://www.imagemagick.org/Usage/windows/

Re: export levels' psd

Posted: 2014-08-25T05:57:23-07:00
by iacoposk8
Thank you very much! you have been very kind.
you can make it variable? I'll explain:
now the script to work it needs to indicate that the [0], [2] etc. .. you can put it all in a loop so that I export all levels and when it encounters a case like this be able to handle it.
and if we could also crop images, it would be perfect!

Re: export levels' psd

Posted: 2014-08-28T07:36:14-07:00
by iacoposk8
is there a way to know if the layer is of type "combine"?

Re: export levels' psd

Posted: 2014-08-28T07:43:07-07:00
by dlemstra
The first 'image/layer' is the combined image.

Re: export levels' psd

Posted: 2014-08-28T08:37:56-07:00
by iacoposk8
but I can understand it via code?
so that if I export a layer in a foreach, if I find one of this type use the code fmw42

Re: export levels' psd

Posted: 2014-08-28T09:02:45-07:00
by fmw42
there is no guarantee that another image will need the same combination of layers that I used in my code for your image. In fact, another image may need totally different processing of layers to achieve what you may want.

I had to write out each layer of your image and examine then separately to see what code was needed to achieve what you wanted.

Re: export levels' psd

Posted: 2014-08-28T09:34:43-07:00
by iacoposk8
and to export the combined layer there is another way?

Re: export levels' psd

Posted: 2014-08-28T09:43:09-07:00
by fmw42
For your combined layer, no. But the first layer of the PSD file should be the combination of all layers flatted. But in your case, that was not what you wanted. So one has to examine each layer and decide how to combine them, if the first layer (image.psd[0]) is not what you want. Or create a new PSD file in Photoshop that does what you want for the combination of all the layers (as the combined layer [0]).

Re: export levels' psd

Posted: 2014-08-28T23:37:59-07:00
by iacoposk8
OK. thank you for your response.
I thought it was easier, because I found so many scripts to photoshop online, even amateur, with a few lines where you could do.
a common thing that I saw in all the script is this:
are hidden all levels, then one by one were displayed and exported.
even doing so you could solve my problem?
thank you :)

Re: export levels' psd

Posted: 2014-08-29T09:39:11-07:00
by fmw42
If all the PDS files have the very same combination of layers, then the code I sent would do what you want. But if the PSD files have other combination of layers, then that same code would not work.