views:

63

answers:

3

I was able to figure a basic word wrap function like this

 $draw = new ImagickDraw();
 $x = 0;
 $y=20;
 $angle = 0;
 $str = "some text for testing of a word wrap in imagemagick";
$str = wordwrap($str, 10,"\r");
$im->annotateImage( $draw, $x, $y, $angle, $str );

and that seems to work ok except that the tracking i think its called you know the space between lines is too much and thoughts or ideas on how to fix this or if there is a better option

+1  A: 

The line height is determined by the font metric. You could of course add a blank line otherwise you would need to render one line at a time and manually specify the offset of the text within the image.

[EDIT] : On OP request, there appears to be a command-line version of it.

shamittomar
so i guess there is no way to specify the font metric ?
mcgrailm
@mcgrailm, updated the answer.
shamittomar
A: 

Sine I could control the spacing I went with rendering the lines each

  $draw = new ImagickDraw();
  $x = 0;
  $y=20;
  $angle = 0;
  $padding = 10;
  $str = "some text for testing of a word wrap in imagemagick";
  $str = wordwrap($str, 10,"\r");
  $str_array = explode("\n",$str);
  foreach($str_array as $line)
    $im->annotateImage( $draw, $x, $y+$padding, $angle, $line );
  }
mcgrailm
A: 

You can have ImageMagic calculate the metrics details for you: http://php.net/manual/en/function.imagick-queryfontmetrics.php.

Marc B
could you explain or give an example of how this lets me change the space between the lines ?
mcgrailm
You can get the line height from the metrics data. Then draw each individual text line and change the starting point for each line based on the height metric with your adjustments in place.
Marc B