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

 <?php
$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.


<?php
$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.


<?php
$input_image 
"folder1/folder2/input_image_12345.jpg";
exec("convert $input_image output_image.jpg");
?>