Rubblewebs

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.

Book

3D Book effect

Book example
 
// Create the "pages" for the book
$cmd = "-size 40x337 xc:#FFF8C6 -stroke '#827B60' -strokewidth 1 ".
"-draw \" line 5,0 5,337 \" -draw \" line 10,0 10,337 \" ".
"-draw \" line 15,0 15,337 \" ".
"-draw \" line 20,0 20,337 \" -draw \" line 25,0 25,337 \" ".
"-draw \" line 30,0 30,337 \" -draw \" line 35,0 35,337 \" ";

exec("convert $cmd pages.png");

// Distort the pages
$cmd = "pages.png -matte -background none -virtual-pixel background ".
" -distort Perspective \"0,0 0,0 40,0 40,6 40,337 40,331 0,337 0,337\" ".
" -trim ";

exec("convert $cmd distort_pages.png");

// Distort the book front page
$cmd = " $input11 -matte -background none ".
" -virtual-pixel background ".
" -distort Perspective \"0,0 20,20 211,0 211,0 211,337 211,337 0,337 20,317\" ".
" -trim ";

exec("convert $cmd distorted_book.png");

// Join the pages to the book
$cmd = " -background none distorted_book.png distort_pages.png +append ";

exec("convert $cmd book.png");

// Delete the tempory images
$delete = array('pages.png','distort_pages.png','distorted_book.png');
foreach ( $delete as $value ) {
    unlink($value);
}

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. For some reason the front page is now upside down - have the distort perspective paramaters changed?


Back