public function drawText(Image $image, $string, $offsetY) { $box = new Box($image->getSize()->getWidth(), $image->getSize()->getHeight() / 4); $fitter = new Fitter($string, $this->getFont()); $fitter->makeTextFitInBox($box); $boxes = $fitter->getTextBoxes(); $start = $fitter->getStartingPointForCenteredBox($image->getSize(), $boxes[0]); foreach ($fitter->getLines() as $k => $line) { $start = $fitter->getStartingPointForCenteredBox($image->getSize(), $boxes[$k], $offsetY); $image->draw()->text($line, $fitter->getFont(), $start); if (version_compare(phpversion("imagick"), "3.0.2", ">=")) { $offsetY += $fitter->getFont()->getSize() * 96 / 72; } else { $offsetY += $fitter->getFont()->getSize(); } } }
/** * Returns the width and height of the image in pixels. * * @return ArrayObject */ public function getSize() { $size = $this->image->getSize(); return $this->arr(['width' => $size->getWidth(), 'height' => $size->getHeight()]); }