This tutorial covers Draw using PHP with Image Magick from the command line. For more information on PHP variables see Lesson I on making backgrounds. | |||||||||||||||||||||
| |||||||||||||||||||||
<? $SIZE="-size 100x80"; $XC="xc:skyblue"; $STROKE="-stroke black -strokewidth 2"; $DRAW="-draw 'line 0,0 100,80'"; $OUT="drawline.gif"; exec ("/usr/bin/convert $SIZE $XC $STROKE $DRAW $OUT"); ?> | LINE | ||||||||||||||||||||
<? $SIZE="-size 100x60"; $XC="xc:skyblue"; $FILL="-fill white"; $STROKE="-stroke black"; $DRAW="-draw 'rectangle 10,10 90,50'"; $OUT="drawrec.gif"; exec ("/usr/bin/convert $SIZE $XC $FILL $STROKE $DRAW $OUT"); ?> | RECTANGLE | ||||||||||||||||||||
<? $SIZE="-size 100x60"; $XC="xc:skyblue"; $FILL="-fill white"; $STROKE="-stroke black -strokewidth 4"; $DRAW="-draw 'roundrectangle 20,10 80,50 20,15'"; $OUT="drawrorec.gif"; exec ("/usr/bin/convert $SIZE $XC $FILL $STROKE $DRAW $OUT"); ?> | ROUND RECTANGLE | ||||||||||||||||||||
<? $SIZE="-size 100x60"; $XC="xc:skyblue"; $FILL="-fill white"; $STROKE="-stroke black -strokewidth 2"; $DRAW="-draw 'arc 20,10 80,50 0,360'"; $OUT="drawarc.gif"; exec ("/usr/bin/convert $SIZE $XC $FILL $STROKE $DRAW $OUT"); ?> | ARC | ||||||||||||||||||||
Same as above with a rectangle drawn under it so you can see the corner parameters as the arc cuts them off. $DRAW="-draw 'rectangle 20,10, 80, 50' -draw 'arc 20,10 80,50 0,360'"; | |||||||||||||||||||||
<? $SIZE="-size 100x60"; $XC="xc:skyblue"; $FILL="-fill white"; $STROKE="-stroke black -strokewidth 2"; $DRAW="-draw 'arc 20,10 80,50 45,270'"; $OUT="drawarcpart.gif"; exec ("/usr/bin/convert $SIZE $XC $FILL $STROKE $DRAW $OUT"); ?> | ARC PART | ||||||||||||||||||||
<? $SIZE="-size 100x80"; $XC="xc:skyblue"; $FILL="-fill red"; $STROKE="-stroke black -strokewidth 2"; $DRAW="-draw 'bezier 5,40 50,10 90,40'"; $OUT="bezier.gif"; exec ("/usr/bin/convert $SIZE $XC $FILL $STROKE $DRAW $OUT"); ?> | BEZIER | ||||||||||||||||||||
$DRAW="-draw 'bezier 10,40 50,-20 90,40'"; | BEZIER | ||||||||||||||||||||
<? $SIZE="-size 100x80"; $XC="xc:skyblue"; $FILL="-fill red"; $STROKE="-stroke black -strokewidth 2"; $DRAW="-draw 'ellipse 50,40 40,30 0,360'"; $OUT="ellipse.gif"; exec ("/usr/bin/convert $SIZE $XC $FILL $STROKE $DRAW $OUT"); ?> | ELLIPSE | ||||||||||||||||||||
<? $SIZE="-size 100x100"; $XC="xc:skyblue"; $FILL="-fill red"; $STROKE="-stroke black -strokewidth 2"; $DRAW="-draw 'circle 50,50 80,80'"; $OUT="drawcircle.gif"; exec ("/usr/bin/convert $SIZE $XC $FILL $STROKE $DRAW $OUT"); ?> | CIRCLE | ||||||||||||||||||||
<? $SIZE="-size 100x80"; $XC="xc:skyblue"; $FILL="-fill red"; $STROKE="-stroke black -strokewidth 2"; $DRAW="-draw 'polyline 0,40 20,10 40,70 60,0 80,80 100,10'"; $OUT="polyline.gif"; exec ("/usr/bin/convert $SIZE $XC $FILL $STROKE $DRAW $OUT"); ?> | POLYLINE | ||||||||||||||||||||
<? $SIZE="-size 72x80"; $XC="xc:skyblue"; $FILL="-fill red"; $STROKE="-stroke black -strokewidth 2"; $DRAW="-draw 'polygon 20,10 50,10 65,25 65,55 50,70 20,70 5,55 5,25 20,10'"; $OUT="polygon.gif"; exec ("/usr/bin/convert $SIZE $XC $FILL $STROKE $DRAW $OUT"); ?> | POLYGON | ||||||||||||||||||||
Path is not currently available from the command line but Mr. C is working on it. Still he recommends that an SVG or MVG script would be easier since the codes can get very large. Here is an SVG image script that can be called with IM from the command line. Put this scrip in a file by itself and call it path.svg. Then create another file called path.php and put the script on the right into that file and it will output the image to your directory. I will be covering Path in a separate tutorial as well as SVG. | |||||||||||||||||||||
<?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg width="100%" height="100%" version="1.1" xmlns="http://www.w3.org/2000/svg"> <path d="M153 334 C153 334 151 334 151 334 C151 339 153 344 156 344 C164 344 171 339 171 334 C171 322 164 314 156 314 C142 314 131 322 131 334 C131 350 142 364 156 364 C175 364 191 350 191 334 C191 311 175 294 156 294 C131 294 111 311 111 334 C111 361 131 384 156 384 C186 384 211 361 211 334 C211 300 186 274 156 274" style="fill:white;stroke:red;stroke-width:2"/> </svg> | PATH <? $IN="path.svg"; $OUT="path.jpg"; exec ("/usr/bin/convert $IN -trim +repage $OUT"); ?> | ||||||||||||||||||||
You can use an image for any of these scripts by substituting the $XC with the image URL, putting the size of the image for the $SIZE, and remove the $FILL color line in both the variable and the command line. | |||||||||||||||||||||
<? $SIZE="-size 199x128"; $XC="angel.gif"; $STROKE="-stroke red -strokewidth 3"; $DRAW="-draw 'line 0,0 199,128''line 199,0 0,128'"; $OUT="drawang.gif"; exec ("/usr/bin/convert $XC $STROKE $DRAW $OUT"); ?> |