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.
$color = "red";
$image = "rose:";
$size = "70x46";
$string = "A Rose by any Name";
// Example 1 - Using concatenate
exec("convert -background none -fill $color -gravity center " .
" -font Candice -size $size caption:\"$string\" " .
" \( $image -negate -flip \) +swap -composite " .
" 1.gif" );
// Example 2 - Using the imagemagick line continuation of \\
exec("convert -background none -fill $color -gravity center \\
-font Candice -size $size caption:$string \\
\( $image -negate -flip \) +swap -composite \\
2.gif" );
// Example 3 - Writing the comand into a variable
$cmd = "-background none -fill $color -gravity center " .
" -font Candice -size $size caption:$string " .
" \( $image -negate -flip \) +swap -composite ";
exec("convert $cmd 3.gif" );
// Example 4 - One long line
exec("convert -background none -fill $color -gravity center -font Candice -size $size caption:$string \( $image -negate -flip \) +swap -composite 4.gif" );
The code above demonstrates the different ways you can write your imagemagick code. It also shows how you can carry your code onto different lines to make it easer to read.
On windows you can use ( ) but on Linux you will need \( \).
Care should also be taken with the quotes and on windows you will need to use \" not '.
I am told it is a good idea to enclose the variables in quotes as some shell versions may interperate it in different ways.
From Anthony on the imagemgagick forums:
What you need to remember is that the given string is decoded three times:
once as a single long string by PHP
once as separate word arguments by some shell
and finally by ImageMagick for format escapes, and quotes in quotes