THESE CODES ARE PROVIDED FOR AN EXAMPLE OF HOW TO USE IMAGEMAGICK WITH PHP. CARE SHOULD BE TAKEN WHEN ACCEPTING USER INPUT.
I TAKE NO RESPONSABILTY FOR ANY PROBLEMS THAT MAY OCCURE WHEN USING ANY OF THIS CODE.
IT IS UP TO YOU TO SECURE THE CODE AND VALIDATE USER INPUT.
// Generate the Spine Image
$cmd = " -size 200x40 xc:lightblue ".
"-pointsize 20 -gravity north -annotate +5+0 \"Rubblewebs\" ".
" -pointsize 10 -gravity south -annotate +0+0 \"Website design\" ".
" -stroke blue -strokewidth 2 -draw \"line 30,0 30,40\" -rotate -90 ";
exec("convert $cmd spine.png ");
// Generate the front cover - text and image
$cmd =" -size 150x200 xc:lightblue ".
" -fill black -pointsize 20 -gravity north -annotate +0+5 \"Rubblewebs\" ".
" -fill blue -pointsize 15 -gravity northeast -annotate +5+28 \"Box Set\" ".
" -fill black -pointsize 15 -gravity south -annotate +0+5 \"Website design\" ".
" -stroke blue -strokewidth 2 -draw \"line 0,169 150,169\" ".
" ( http://www.rubblewebs.co.uk/images/logo.png -resize 100x100 ) ".
" -gravity center -compose multiply -composite ";
exec("convert $cmd front.png ");
// Distort both images and merge together.
$cmd =" spine.png -virtual-pixel background -background none ".
" +distort Perspective \"0,0 -40,20 0,199 -40,179 39,199 0,199 39,0 0,0\" ".
" ( front.png ".
" +distort Perspective \"0,0 0,0 0,199 0,199 149,199 99,169 149,0 99,30\" ".
" ) -background none -layers merge +repage -trim ";
exec("convert $cmd box_set.png ");
// Delete the tempory images
$delete = array( 'spine.png','front.png' );
foreach ( $delete as $value ) {
unlink( $value );
}
If your "distortion" is larger than the original image you need to use +distort not -distort
If on Linux you will need to escape the ( ) with \
png type images are being used to save on jpg compression everytime they are saved;
also the backgrounds are transparent and jpg does not support transparency.
Code updated as per recomendations of Anthony on the IM forum.
The distortion settings were changed and this uses the later versions of that