public function testGetStartingPointForCenteredBox()
 {
     $text = 'Test not exceeding';
     $font = $this->getFont();
     $fitter = new Fitter($text, $font);
     $box = new Box(500, 150);
     $center = new Box(100, 150);
     $result = $fitter->getStartingPointForCenteredBox($box, $center);
     $this->assertEquals(200, $result->getX());
     $this->assertEquals(0, $result->getY());
     $offset = 10;
     $resultWithOffset = $fitter->getStartingPointForCenteredBox($box, $center, $offset);
     $this->assertEquals(200, $resultWithOffset->getX());
     $this->assertEquals($offset, $resultWithOffset->getY());
 }
 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();
         }
     }
 }