Gravity

Gravity is used to set the position of the object on the background; it uses the points of a compass: North, Northeast, East, Southeast, South, Southwest, west, Northwest and center

Finer positioning can be acheved using the -geometry operator

Image showing the gravity locations
<?php
exec
(" convert -size 500x300 xc:white -font ../jd.ttf -pointsize 30 \\
-draw \"gravity center fill black text 0,0 'Center' \" \\
-draw \"gravity North fill black text 0,0 'North' \" \\
-draw \"gravity Northeast fill black text 0,0 'Northeast' \" \\
-draw \"gravity East fill black text 0,0 'East' \" \\
-draw \"gravity Southeast fill black text 0,0 'Southeast' \" \\
-draw \"gravity South fill black text 0,0 'South' \" \\
-draw \"gravity Southwest fill black text 0,0 'Southwest' \" \\
-draw \"gravity West fill black text 0,0 'West' \" \\
-draw \"gravity Northwest fill black text 0,0 'Northwest' \" \\
-bordercolor black -border 1x1 gravity.jpg" 
);
?>

In this case I think a neater way of writting the code is using more php as below.


<?php
// Array of values
$arr = array("North""Northeast""East""Southeast""South""Southwest""West""Northwest",
 
"Center");
// Set $command
$command ="";
// Setup loop for the array
foreach ($arr as $value) {
// Create the individual draw commands and add them to the previous value of $command
$command .= " -draw \"gravity $value fill black text 0,0 $value \" " ;  }
// Create the image using php
exec(" convert -size 500x300 xc:white -font ../jd.ttf -pointsize 30 \\
$command bordercolor black -border 1x1 gravity.jpg" );
?>