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.

Variables

Variables can be used to pass information to the ImageMagick code. The variables can come from a form or from some other part of the code; for instance the image size when using


$size = getimagesize('sunflower.jpg');




The variables sometimes need to be isolated from the code and I use { and } for that. You can use ' ' around the variable.


$size = getimagesize('sunflower.jpg');
exec("convert -size {$size[0]}x{$size[1]} input_image.jpg -resize 100x100 output_image.jpg");




If you have a long path I find it easier to put the path into a variable.


$input_image = "folder1/folder2/input_image_12345.jpg";
exec("convert $input_image output_image.jpg");