예제 #1
0
파일: Drawer.php 프로젝트: halid/Imagine
 /**
  * (non-PHPdoc)
  * @see Imagine\Draw\DrawerInterface::text()
  */
 public function text($string, Font $font, PointInterface $position, $angle = 0)
 {
     try {
         $pixel = $this->getColor($font->getColor());
         $text = new \ImagickDraw();
         $text->setFont($font->getFile());
         $text->setFontSize($font->getSize());
         $text->setFillColor($pixel);
         $text->setTextAntialias(true);
         $info = $this->imagick->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->imagick->annotateImage($text, $position->getX() + $x1 + $xdiff, $position->getY() + $y2 + $ydiff, $angle, $string);
         $pixel->clear();
         $pixel->destroy();
         $text->clear();
         $text->destroy();
     } catch (\ImagickException $e) {
         throw new RuntimeException('Draw text operation failed', $e->getCode(), $e);
     }
 }
예제 #2
0
파일: Drawer.php 프로젝트: halid/Imagine
 /**
  * (non-PHPdoc)
  * @see Imagine\Draw\DrawerInterface::text()
  */
 public function text($string, Font $font, PointInterface $position, $angle = 0)
 {
     $angle = -1 * $angle;
     $fontsize = $font->getSize();
     $fontfile = $font->getFile();
     $info = imageftbbox($fontsize, $angle, $fontfile, $string);
     $xs = array($info[0], $info[2], $info[4], $info[6]);
     $ys = array($info[1], $info[3], $info[5], $info[7]);
     $width = abs(max($xs) - min($xs));
     $height = abs(max($ys) - min($ys));
     $xdiff = 0 - min($xs) + $position->getX();
     $ydiff = 0 - min($ys) + $position->getY();
     foreach ($xs as &$x) {
         $x += $xdiff;
     }
     foreach ($ys as &$y) {
         $y += $ydiff;
     }
     if (false === imagealphablending($this->resource, true)) {
         throw new RuntimeException('Font mask operation failed');
     }
     if (false === imagefttext($this->resource, $fontsize, $angle, $xs[0], $ys[0], $this->getColor($font->getColor()), $fontfile, $string)) {
         throw new RuntimeException('Font mask operation failed');
     }
     if (false === imagealphablending($this->resource, false)) {
         throw new RuntimeException('Font mask operation failed');
     }
     return $this;
 }