Example #1
0
 /**
  * (non-PHPdoc)
  * @see Imagine\Draw\DrawerInterface::text()
  */
 public function text($string, AbstractFont $font, PointInterface $position, $angle = 0)
 {
     try {
         $pixel = $this->getColor($font->getColor());
         $text = new \GmagickDraw();
         $text->setfont($font->getFile());
         $text->setfontsize($font->getSize());
         $text->setfillcolor($pixel);
         $info = $this->gmagick->queryfontmetrics($text, $string);
         $rad = deg2rad($angle);
         $cos = cos($rad);
         $sin = sin($rad);
         $x1 = round(0 * $cos - 0 * $sin);
         $x2 = round($info['textWidth'] * $cos - $info['textHeight'] * $sin);
         $y1 = round(0 * $sin + 0 * $cos);
         $y2 = round($info['textWidth'] * $sin + $info['textHeight'] * $cos);
         $xdiff = 0 - min($x1, $x2);
         $ydiff = 0 - min($y1, $y2);
         $this->gmagick->annotateimage($text, $position->getX() + $x1 + $xdiff, $position->getY() + $y2 + $ydiff, $angle, $string);
         $pixel = null;
         $text = null;
     } catch (\GmagickException $e) {
         throw new RuntimeException('Draw text operation failed', $e->getCode(), $e);
     }
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function text($string, AbstractFont $font, PointInterface $position, $angle = 0)
 {
     try {
         $pixel = $this->getColor($font->getColor());
         $text = new \GmagickDraw();
         $text->setfont($font->getFile());
         /**
          * @see http://www.php.net/manual/en/imagick.queryfontmetrics.php#101027
          *
          * ensure font resolution is the same as GD's hard-coded 96
          */
         $text->setfontsize((int) ($font->getSize() * (96 / 72)));
         $text->setfillcolor($pixel);
         $info = $this->gmagick->queryfontmetrics($text, $string);
         $rad = deg2rad($angle);
         $cos = cos($rad);
         $sin = sin($rad);
         $x1 = round(0 * $cos - 0 * $sin);
         $x2 = round($info['textWidth'] * $cos - $info['textHeight'] * $sin);
         $y1 = round(0 * $sin + 0 * $cos);
         $y2 = round($info['textWidth'] * $sin + $info['textHeight'] * $cos);
         $xdiff = 0 - min($x1, $x2);
         $ydiff = 0 - min($y1, $y2);
         $this->gmagick->annotateimage($text, $position->getX() + $x1 + $xdiff, $position->getY() + $y2 + $ydiff, $angle, $string);
         $pixel = null;
         $text = null;
     } catch (\GmagickException $e) {
         throw new RuntimeException('Draw text operation failed', $e->getCode(), $e);
     }
     return $this;
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function text($string, AbstractFont $font, PointInterface $position, $angle = 0, $width = null)
 {
     try {
         $pixel = $this->getColor($font->getColor());
         $text = new \GmagickDraw();
         $text->setfont($font->getFile());
         /**
          * @see http://www.php.net/manual/en/imagick.queryfontmetrics.php#101027
          *
          * ensure font resolution is the same as GD's hard-coded 96
          */
         $text->setfontsize((int) ($font->getSize() * (96 / 72)));
         $text->setfillcolor($pixel);
         $info = $this->gmagick->queryfontmetrics($text, $string);
         // $rad  = deg2rad($angle);
         // $cos  = cos($rad);
         // $sin  = sin($rad);
         // $x1 = round(0 * $cos - 0 * $sin);
         // $x2 = round($info['textWidth'] * $cos - $info['textHeight'] * $sin);
         // $y1 = round(0 * $sin + 0 * $cos);
         // $y2 = round($info['textWidth'] * $sin + $info['textHeight'] * $cos);
         // $xdiff = 0 - min($x1, $x2);
         // $ydiff = 0 - min($y1, $y2);
         if ($width !== null) {
             throw new NotSupportedException('Gmagick doesn\'t support queryfontmetrics function for multiline text', 1);
         }
         // $this->gmagick->annotateimage($text, $position->getX() + $x1 + $xdiff, $position->getY() + $y2 + $ydiff, $angle, $string);
         $deltaX = $info['characterWidth'] * sin(deg2rad($angle));
         $deltaY = $info['characterHeight'];
         $posX = $position->getX() - $deltaX;
         if ($posX < 0) {
             $posX = 0;
         }
         $this->gmagick->annotateimage($text, $posX, $position->getY() + $deltaY, $angle, $string);
         unset($pixel, $text);
     } catch (\GmagickException $e) {
         throw new RuntimeException('Draw text operation failed', $e->getCode(), $e);
     }
     return $this;
 }