Google+
This website uses Google doubleclick cookies for advertising. They are small text files we put in your browser to track usage of our site but they don't tell us who you are. Your use of this site implies your consent to their use.
For more information please read the privicy policy link at the bottom of the page.
psd files cause problems; mainly due to the layers. The examples below are from a psd file with a transparent background layer, an image of some boots with the area around the boots erased to background ( transparent ) and a text layer.
I have added the border on display so the transparent areas show up.
NOTE: When you look at the first example you will see the code created 4 images the finished image and all the layers; so for example this psd file has:
layer[0] = The complete image
layer[1] = The background layer
layer[2] = The image layer
layer[3] = The text layer
So to convert the complete image and ignore the layers you would use:
<?php
exec("convert boots.psd[0] -thumbnail 340x340 boots_png.png");
?>
This is only for images that have not been "merged" as they will only have the one layer.
Converting to a png gives 4 different images named boots_png-0.png etc.
<?php
exec("convert boots.psd -thumbnail 340x340 boots_png.png");
?>
Converting to a gif gives this "flashing" image.
<?php
exec("convert boots.psd -thumbnail 340x340 boots_gif.gif");
?>

Converting to a jpg gives 4 different images named boots_jpg-0.jpg etc.
<?php
exec("convert boots.psd -thumbnail 340x340 boots_jpg.jpg");
?>
Note: The background/transparency comes out black as jpg does not support transparency
Converting to a png gives 2 images named boots_png-0.png etc.
<?php
exec("convert boots_merged.psd -thumbnail 340x340 boots_merged_png.png");
?>
Converting to a gif still gives the "flashing" image.
<?php
exec("convert boots_merged.psd -thumbnail 340x340 boots_merged_gif.gif");
?>

Converting to a jpg gives 2 images named boots_jpg-0.jpg etc.
<?php
exec("convert boots_merged.psd -thumbnail 340x340 boots_merged_jpg.jpg");
?>
<?php
exec("convert 'boots.psd[2]' boots_layer_2.png");
?>

<?php
exec("convert boots.psd -flatten flat_boots.jpg");
?>

There are some assumptions being mage with this code - you know which layers you want to work on; which order they are in and where there are supposed to be on the image !
But it will work with this code:
Note: this has used ImageMagick to resize or whatever other comands have been done
<?php
$size = getimagesize("boots_png-2.png");
$cmd = " -size '$size[0]'x'$size[1]' xc:none ".
" boots_png-2.png -gravity center -composite boots_png-3.png ".
" -gravity south -composite ";
exec("convert $cmd composite_boots.png");
?>

Note: this is working directly with the psd layers
<?php
$size = getimagesize("boots.psd");
$cmd = " -size '$size[0]'x'$size[1]' xc:none ".
" 'boots.psd[2]' -gravity center -composite 'boots.psd[3]' ".
" -gravity south -composite ";
exec("convert $cmd composite_boots_psd.png");
?>

A couple of notes first:
<?php
exec("convert image1.png image2.png image3.png");
?>