Imagick::annotateImage

(PECL imagick 2.0.0)

Imagick::annotateImageДобавляет текстовый комментарий на изображение

Описание

bool Imagick::annotateImage ( ImagickDraw $draw_settings , float $x , float $y , float $angle , string $text )

Добавляет текстовый комментарий на изображение.

Список параметров

draw_settings

Объект ImagickDraw с настройками наносимого текста

x

Горизонтальное смещение в пикселях слева от текста

y

Вертикальное смещение в пикселях к базовому тексту

angle

Угол под которым выводится текст. Положительное значение: направление от верхнего левого угла до нижнего правого угла. Отрицательное значение: от нижнего левого угла до верхнего правого угла.

text

Строка с текстом

Возвращаемые значения

В случае успешной работы возвращает TRUE.

Примеры

Пример #1 Использование Imagick::annotateImage():

Добавление текста к пустому изображению

<?php
/* Создаем объекты */
$image = new Imagick();
$draw = new ImagickDraw();
$pixel = new ImagickPixel'gray' );

/* Новое изображение */
$image->newImage(80075$pixel);

/* Черный текст */
$draw->setFillColor('black');

/* Настройки шрифта */
$draw->setFont('Bookman-DemiItalic');
$draw->setFontSize30 );

/* Создаем текст */
$image->annotateImage($draw10450'The quick brown fox jumps over the lazy dog');

/* Устанавливаем формат изображения */
$image->setImageFormat('png');

/* Выводим изображение с заголовками */
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.
2007-08-23 15:37:15
http://php5.kiev.ua/manual/ru/imagick.annotateimage.html
$image->annotateImage($draw, 10, 45, 0, 'The quick brown fox');

If the third parameter, the 'Y' value, is 0, the text will be invisible because the text is printed ABOVE the image - not on the image. 

The solution is to start, depending on your chosen font size, with a Y value of about 40 and experiment.

[Also:]

When wishing to print some text on a photograph and make that text sufficiently contrasting to the background image, use a 4 byte code for colour and transparency.

It is the same 4 byte code using by the parameter '-undercolor' in ImageMagick's command lime instruction 'convert'.

The first 3 bytes are the RGB colour code and the fourth byte is the transparency byte.

<?php
   $picin 
= new Imagick($pic1);
   
$picin->scaleimage(800,0);
   
$height $picin->getimageheight();

   
$draw = new ImagickDraw();
   
$draw->setFillColor('#ffff00');
   
$draw->setFont('Eurostile');
   
$draw->setFontSize(21);
   
$draw->setTextUnderColor('#ff000088');
   
$picin->annotateImage($draw,40,$height-10,0,"Hallo");

   
$picin->writeimage($pic6);
?>

The example code produces yellow text on a semi-transparent red background.

$pic1 and $pic6 were previously defined as directory/file strings.
2011-09-08 11:13:56
http://php5.kiev.ua/manual/ru/imagick.annotateimage.html
Does not work with CMYK color values and images. Only RGB.
2016-08-26 10:30:19
http://php5.kiev.ua/manual/ru/imagick.annotateimage.html
Автор:
Note that $angle is in DEGREES and rotates CLOCKWISE. Negative numbers are allowed.
2023-12-22 22:39:24
http://php5.kiev.ua/manual/ru/imagick.annotateimage.html

    Поддержать сайт на родительском проекте КГБ