PHP 8.5.0 Beta 1 available for testing

Voting

: four plus one?
(Example: nine)

The Note You're Voting On

waage
17 years ago
You can use this to center a text within a box

<?php

$data
= "Hello world";

$text = new ImagickDraw();
$text->setFontSize(12);
$text->setFont("Arial");

$boxWidth = 210;

$im = new Imagick();

$fm = $im->queryFontMetrics($text, $data, false);

$textXLoc = ($boxWidth / 2) - ($fm["textWidth"] / 2);

?>

$textXLoc is now the starting location you need to use to feed to your annotateImage() function.

<< Back to user notes page

To Top