當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ImagickDraw::setResolution方法代碼示例

本文整理匯總了PHP中ImagickDraw::setResolution方法的典型用法代碼示例。如果您正苦於以下問題:PHP ImagickDraw::setResolution方法的具體用法?PHP ImagickDraw::setResolution怎麽用?PHP ImagickDraw::setResolution使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ImagickDraw的用法示例。


在下文中一共展示了ImagickDraw::setResolution方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: calculateTextSize

 /**
  * Calculates size for bounding box of string written in given font.
  *
  * @param string        $string
  * @param FontInterface $font
  *
  * @return bool|Box Instance of Box object, false on error
  */
 public static function calculateTextSize($string, FontInterface $font)
 {
     $imagine = Tygh::$app['image'];
     if ($imagine instanceof \Imagine\Imagick\Imagine && class_exists('ImagickDraw')) {
         $text = new \ImagickDraw();
         $text->setFont($font->getFile());
         if (version_compare(phpversion("imagick"), "3.0.2", ">=")) {
             $text->setResolution(96, 96);
             $text->setFontSize($font->getSize());
         } else {
             $text->setFontSize((int) ($font->getSize() * (96 / 72)));
         }
         $imagick = new \Imagick();
         $info = $imagick->queryFontMetrics($text, $string);
         $text->clear();
         $text->destroy();
         $imagick->clear();
         $imagick->destroy();
         return new Box($info['textWidth'], $info['textHeight']);
     }
     if ($imagine instanceof \Imagine\Gd\Imagine && function_exists('imagettfbbox')) {
         $ttfbbox = imagettfbbox($font->getSize(), 0, $font->getFile(), $string);
         return new Box(abs($ttfbbox[2]), abs($ttfbbox[7]));
     }
     return false;
 }
開發者ID:ambient-lounge,項目名稱:site,代碼行數:34,代碼來源:ImageHelper.php

示例2: box

 /**
  * {@inheritdoc}
  */
 public function box($string, $angle = 0)
 {
     $text = new \ImagickDraw();
     $text->setFont($this->file);
     /**
      * @see http://www.php.net/manual/en/imagick.queryfontmetrics.php#101027
      *
      * ensure font resolution is the same as GD's hard-coded 96
      */
     if (version_compare(phpversion("imagick"), "3.0.2", ">=")) {
         $text->setResolution(96, 96);
         $text->setFontSize($this->size);
     } else {
         $text->setFontSize((int) ($this->size * (96 / 72)));
     }
     $info = $this->imagick->queryFontMetrics($text, $string);
     $box = new Box($info['textWidth'], $info['textHeight']);
     return $box;
 }
開發者ID:anillaogi016,項目名稱:zend-admin,代碼行數:22,代碼來源:Font.php

示例3: text

 /**
  * {@inheritdoc}
  */
 public function text($string, AbstractFont $font, PointInterface $position, $angle = 0, $width = null)
 {
     try {
         $pixel = $this->getColor($font->getColor());
         $text = new \ImagickDraw();
         $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
          */
         if (version_compare(phpversion("imagick"), "3.0.2", ">=")) {
             $text->setResolution(96, 96);
             $text->setFontSize($font->getSize());
         } else {
             $text->setFontSize((int) ($font->getSize() * (96 / 72)));
         }
         $text->setFillColor($pixel);
         $text->setTextAntialias(true);
         $info = $this->imagick->queryFontMetrics($text, $string);
         $rad = deg2rad($angle);
         $cos = cos($rad);
         $sin = sin($rad);
         // round(0 * $cos - 0 * $sin)
         $x1 = 0;
         $x2 = round($info['characterWidth'] * $cos - $info['characterHeight'] * $sin);
         // round(0 * $sin + 0 * $cos)
         $y1 = 0;
         $y2 = round($info['characterWidth'] * $sin + $info['characterHeight'] * $cos);
         $xdiff = 0 - min($x1, $x2);
         $ydiff = 0 - min($y1, $y2);
         if ($width !== null) {
             $string = $this->wrapText($string, $text, $angle, $width);
         }
         $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);
     }
     return $this;
 }
開發者ID:jmstan,項目名稱:craft-website,代碼行數:47,代碼來源:Drawer.php

示例4: Imagick

<?php

$im = new Imagick();
$im->newImage(1000, 1000, "white", "png");
$draw = new ImagickDraw();
$draw->setFont(__DIR__ . '/anonymous_pro_minus.ttf');
$draw->setFontSize(72);
$draw->setResolution(10, 10);
$small = $im->queryFontMetrics($draw, "Hello World");
$draw->setResolution(300, 300);
$large = $im->queryFontMetrics($draw, "Hello World");
var_dump($small['textWidth'] < $large['textWidth']);
echo "OK\n";
開發者ID:badlamer,項目名稱:hhvm,代碼行數:13,代碼來源:015_imagickdrawsetresolution.php


注:本文中的ImagickDraw::setResolution方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。