(PECL imagick 2.0.0)
Imagick::annotateImage — Annotates an image with text
Annotates an image with text.
The ImagickDraw object that contains settings for drawing the text
Horizontal offset in pixels to the left of text
Vertical offset in pixels to the baseline of text
The angle at which to write the text
The string to draw
Liefert TRUE bei Erfolg.
Beispiel #1 Using Imagick::annotateImage():
Annotate text on an empty image
<?php
/* Create some objects */
$image = new Imagick();
$draw = new ImagickDraw();
$pixel = new ImagickPixel( 'gray' );
/* New image */
$image->newImage(800, 75, $pixel);
/* Black text */
$draw->setFillColor('black');
/* Font properties */
$draw->setFont('Bookman-DemiItalic');
$draw->setFontSize( 30 );
/* Create text */
$image->annotateImage($draw, 10, 45, 0, 'The quick brown fox jumps over the lazy dog');
/* Give image a format */
$image->setImageFormat('png');
/* Output the image with headers */
header('Content-type: image/png');
echo $image;
?>
If ImagickDraw::setGravity ( int $gravity ) has been set, e,g; with $gravity= imagick::GRAVITY_CENTER.
Then, the x and y values offset the text from where the gravity setting would have placed it.
If the example included: $draw->setGravity (Imagick::GRAVITY_CENTER);
$image->annotateImage($draw, 10, 45, 0, 'The quick brown fox jumps over the lazy dog');
The text would be rendered to the right 10px and down 45px from the center.
Gravity constants are very useful as they can save having to calculate the placement of variable text strings and font sizes.