Imagick::annotateImage

(PECL imagick 2, PECL imagick 3)

Imagick::annotateImage β€” ДобавляСт тСкстовый ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ Π½Π° ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅

ОписаниС

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

ДобавляСт тСкстовый ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ Π½Π° ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅.

Бписок ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΎΠ²

draw_settings

ΠžΠ±ΡŠΠ΅ΠΊΡ‚ ImagickDraw с настройками наносимого тСкста

x

Π“ΠΎΡ€ΠΈΠ·ΠΎΠ½Ρ‚Π°Π»ΡŒΠ½ΠΎΠ΅ смСщСниС Π² пиксСлях слСва ΠΎΡ‚ тСкста

y

Π’Π΅Ρ€Ρ‚ΠΈΠΊΠ°Π»ΡŒΠ½ΠΎΠ΅ смСщСниС Π² пиксСлях ΠΊ Π±Π°Π·ΠΎΠ²ΠΎΠΌΡƒ тСксту

angle

Π£Π³ΠΎΠ» ΠΏΠΎΠ΄ ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΌ выводится тСкст. ΠŸΠΎΠ»ΠΎΠΆΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎΠ΅ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅: Π½Π°ΠΏΡ€Π°Π²Π»Π΅Π½ΠΈΠ΅ ΠΎΡ‚ Π²Π΅Ρ€Ρ…Π½Π΅Π³ΠΎ Π»Π΅Π²ΠΎΠ³ΠΎ ΡƒΠ³Π»Π° Π΄ΠΎ Π½ΠΈΠΆΠ½Π΅Π³ΠΎ ΠΏΡ€Π°Π²ΠΎΠ³ΠΎ ΡƒΠ³Π»Π°. ΠžΡ‚Ρ€ΠΈΡ†Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΠ΅ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅: ΠΎΡ‚ Π½ΠΈΠΆΠ½Π΅Π³ΠΎ Π»Π΅Π²ΠΎΠ³ΠΎ ΡƒΠ³Π»Π° Π΄ΠΎ Π²Π΅Ρ€Ρ…Π½Π΅Π³ΠΎ ΠΏΡ€Π°Π²ΠΎΠ³ΠΎ ΡƒΠ³Π»Π°.

text

Π‘Ρ‚Ρ€ΠΎΠΊΠ° с тСкстом

Π’ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅ΠΌΡ‹Π΅ значСния

Ѐункция Π² случаС ΡƒΡΠΏΠ΅ΡˆΠ½ΠΎΠΉ Ρ€Π°Π±ΠΎΡ‚Ρ‹ Π²ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅Ρ‚ true.

ΠŸΡ€ΠΈΠΌΠ΅Ρ€Ρ‹

ΠŸΡ€ΠΈΠΌΠ΅Ρ€ #1 ΠŸΡ€ΠΈΠΌΠ΅Ρ€ использования Imagick::annotateImage():

Π”ΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ тСкста ΠΊ пустому ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΡŽ

<?php
/* Π‘ΠΎΠ·Π΄Π°Ρ‘ΠΌ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚Ρ‹ */
$image = new Imagick();
$draw = new ImagickDraw();
$pixel = new ImagickPixel( 'gray' );

/* НовоС ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ */
$image->newImage(800, 75, $pixel);

/* Π§Ρ‘Ρ€Π½Ρ‹ΠΉ тСкст */
$draw->setFillColor('black');

/* Настройки ΡˆΡ€ΠΈΡ„Ρ‚Π° */
$draw->setFont('Bookman-DemiItalic');
$draw->setFontSize( 30 );

/* Π‘ΠΎΠ·Π΄Π°Ρ‘ΠΌ тСкст */
$image->annotateImage($draw, 10, 45, 0, 'The quick brown fox jumps over the lazy dog');

/* УстанавливаСм Ρ„ΠΎΡ€ΠΌΠ°Ρ‚ изобраТСния */
$image->setImageFormat('png');

/* Π’Ρ‹Π²ΠΎΠ΄ΠΈΠΌ ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ с Π·Π°Π³ΠΎΠ»ΠΎΠ²ΠΊΠ°ΠΌΠΈ */
header('Content-type: image/png');
echo
$image;

?>

Π‘ΠΌΠΎΡ‚Ρ€ΠΈΡ‚Π΅ Ρ‚Π°ΠΊΠΆΠ΅

  • ImagickDraw::annotation() - РисуСт тСкст Π½Π° ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ΅
  • ImagickDraw::setFont() - УстанавливаСт ΡƒΠΊΠ°Π·Π°Π½Π½Ρ‹ΠΉ ΡˆΡ€ΠΈΡ„Ρ‚ для использования ΠΏΡ€ΠΈ Π°Π½Π½ΠΎΡ‚ΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠΈ тСкстом
οΌ‹Π”ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ

ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΡ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Π΅ΠΉ 4 notes

up
9
alan at ridersite dot org ΒΆ
18 years ago
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.
up
3
www dot query at gmail dot com ΒΆ
14 years ago
$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.
up
1
yakuza88 at op dot pl ΒΆ
9 years ago
Does not work with CMYK color values and images. Only RGB.
up
0
tuxedobob ΒΆ
2 years ago
Note that $angle is in DEGREES and rotates CLOCKWISE. Negative numbers are allowed.