示例#1
0
文件: Imanee.php 项目: robth82/imanee
 /**
  * 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;
 }
示例#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;
 }
示例#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);
 }