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.