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.
Imagick::annotateImage
(PECL imagick 2.0.0)
Imagick::annotateImage — Anota una imagen con texto
Descripción
bool Imagick::annotateImage
( ImagickDraw $draw_settings
, float $x
, float $y
, float $angle
, string $text
)
Anota una imagen con texto.
Parámetros
- draw_settings
-
El objeto ImagickDraw que contiene la configuración para el dibujo de texto
- x
-
El índice horizontal en píxeles a la izquierda del texto
- y
-
El índice vertical en píxeles de la línea base del texto
- angle
-
El ángulo en el que se escribe el texto
- text
-
La cadena a dibujar
Valores devueltos
Devuelve TRUE en caso de éxito.
Ejemplos
Example #1 Usar Imagick::annotateImage():
Anotar texto en una imagen vacía
<?php
/* Crear algunos objetos */
$imagen = new Imagick();
$dibujo = new ImagickDraw();
$píxel = new ImagickPixel( 'gray' );
/* Nueva imagen */
$imagen->newImage(800, 75, $píxel);
/* Texto negro */
$dibujo->setColor('black');
/* Propiedades de la fuente */
$dibujo->setFont('Bookman-DemiItalic');
$dibujo->setFontSize( 30 );
/* Crear texto */
$imagen->annotateImage($dibujo, 10, 45, 0, 'The quick brown fox jumps over the lazy dog');
/* Dar a la imagen un formato */
$imagen->setImageFormat('png');
/* Imprimir la imagen con cabeceras */
header('Content-type: image/png');
echo $imagen;
?>
Ver también
- ImagickDraw::annotation() - Dibuja texto en la imagen
- ImagickDraw::setFont() - Establece la fuente especificada completamente para usarla cuando se escribe texto
alan at ridersite dot org
23-Aug-2007 07:37
