PHPCon Poland 2024


(PECL imagick 2, PECL imagick 3)

Imagick::annotateImageGörüntüye bir metin çizer


public Imagick::annotateImage(
    ImagickDraw $çizim_ayarı,
    float $x,
    float $y,
    float $açı,
    string $metin
): bool

Görüntüye bir metin çizer.

Bağımsız Değişkenler


Metni çizmekte kullanılacak ayarları içeren ImagickDraw nesnesi.


Metnin ilk harfinin taban çizgisi başlangıcının X konumu.


Metnin ilk harfinin taban çizgisi başlangıcının Y konumu.


Metnin yazılacağı açı.


Çizilecek dizge.

Dönen Değerler

Başarı durumunda true döner.


Örnek 1 - Imagick::annotateImage() örneği

Boş bir tuvale bir metin çizelim.

// Nesneleri oluştur
$image = new Imagick();
$draw = new ImagickDraw();
$pixel = new ImagickPixel( 'gray' );

// Yeni görüntü
$image->newImage(800, 75, $pixel);

// Metin siyah olsun

// Yazı tipi özelliklerini belirt
$draw->setFontSize( 30 );

// Metni çiz
$image->annotateImage($draw, 10, 45, 0, 'The quick brown fox jumps over the lazy dog');

// Resim biçemi

// Resmi çıktıla
header('Content-Type: image/png');


Ayrıca Bakınız

add a note

User Contributed Notes 4 notes

alan at ridersite dot org
16 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.
www dot query at gmail dot com
12 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.


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.

= new Imagick($pic1);
$height = $picin->getimageheight();

$draw = new ImagickDraw();


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

$pic1 and $pic6 were previously defined as directory/file strings.
yakuza88 at op dot pl
7 years ago
Does not work with CMYK color values and images. Only RGB.
5 months ago
Note that $angle is in DEGREES and rotates CLOCKWISE. Negative numbers are allowed.
To Top