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.
Automatic word wrapping
$cmd = " -size 236x130 xc:lightblue -fill black -font verdana.ttf "." -pointsize 25 -gravity NorthWest "." -annotate +0+0 \"The quick red fox jumped over the lazy brown dog.\" ";exec("convert $cmd annotate1.jpg");
Forced word wrapping
$cmd = " -size 236x130 xc:lightblue -fill black -font verdana.ttf "." -pointsize 25 -gravity NorthWest "." -annotate +0+0 \"The quick red fox\\\njumped over\\\nthe lazy brown\\\ndog.\" ";exec("convert $cmd annotate2.jpg");
Normal line feeds - Using a normal end of line on the text inside the " "
exec("convert -size 236x130 xc:lightblue -fill black -font verdana.ttf \\\-pointsize 25 -gravity NorthWest \\\-annotate +0+0 \"The quick red foxjumped over thelazy brown dog.\" annotate3.jpg");
Using NorthWest aligns the text left and NorthEast aligns the text right;
as well as locating the text on the background.
Automatic word wrapping
exec("convert -size 230x130 -background lightblue -font verdana.ttf -pointsize 25 \\\-gravity NorthWest caption:\"The quick red fox jumped over the lazy brown dog.\" \\\-flatten caption1.jpg");
Forced word wrapping
exec("convert -size 230x130 -background lightblue -font verdana.ttf -pointsize 25 \\\-gravity NorthWest caption:\"The quick red fox\\\njumped over\\\nthe lazy brown dog.\" \\\-flatten caption2.jpg");
Normal line feeds - Using a normal end of line on the text inside the " "
exec("convert -size 230x130 -background lightblue -font verdana.ttf -pointsize 25 \\\-gravity NorthWest caption:\"The quick red foxjumped over thelazy brown dog.\" \\\-flatten caption4.jpg");
Select font to fit image size
exec("convert -size 230x130 -background lightblue -font verdana.ttf \\\-gravity NorthWest \\\caption:\"The quick red fox jumped over the lazy brown dog.\" -flatten caption3.jpg");
Automatic word wrapping
exec("convert -size 230x130 xc:lightblue -font verdana.ttf -pointsize 25 \\\-draw \"gravity NorthWest fill black text 0,0 \'The quick red fox jumped over the lazy brown dog.\'\"\\\draw2.jpg");
Forced word wrapping
exec("convert -size 230x130 xc:lightblue -font verdana.ttf -pointsize 25 \\\-draw \"gravity NorthWest fill black text 0,0 \'The quick red fox\\\njumped over\\\nthe lazy brown dog.\'\"\\\draw2.jpg");
Normal line feeds - Using a normal end of line on the text inside the ' '
exec("convert -size 230x130 xc:lightblue -font verdana.ttf -pointsize 25 -draw \"gravity NorthWest fill black text 0,0 \'The quick red foxjumped overthe lazy brown dog.\'\" draw3.jpg");
exec("convert -background lightblue -fill black -font verdana.ttf -pointsize 25 -size 230x caption:@text.txt caption_file.gif");