Ejemplo n.º 1
0
 /**
  * Adjusts the font size of the Drawer object to fit a text in the desired width
  * @param $text
  * @param Drawer $drawer
  * @param $width
  * @return Drawer
  * @throws UnsupportedMethodException
  */
 public function adjustFontSize($text, Drawer $drawer, $width)
 {
     if (!$this->resource instanceof ImageWritableInterface) {
         throw new UnsupportedMethodException("This method is not supported by the ImageResource in use.");
     }
     $fontSize = 0;
     $metrics['width'] = 0;
     while ($metrics['width'] <= $width) {
         $drawer->setFontSize($fontSize);
         $metrics = $this->resource->getTextGeometry($text, $drawer);
         $fontSize++;
     }
     return $drawer;
 }
Ejemplo n.º 2
0
 /**
  * Translates the Drawer object to a ImagickDraw
  * @param Drawer $drawer
  * @return \ImagickDraw
  */
 public function getImagickDraw(Drawer $drawer)
 {
     $imdraw = new \ImagickDraw();
     $imdraw->setFont($drawer->getFont());
     $imdraw->setFillColor($drawer->getFontColor());
     $imdraw->setFontSize($drawer->getFontSize());
     $imdraw->setTextAlignment($drawer->getTextAlign());
     return $imdraw;
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function annotate($text, $coordX, $coordY, $angle, Drawer $drawer)
 {
     $color = GDPixel::load($drawer->getFontColor(), $this->getResource());
     return imagettftext($this->getResource(), $this->getFontSize($drawer), $angle, $coordX, $coordY, $color, $drawer->getFont(), $text);
 }