当前位置: 首页>>代码示例>>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;未经允许,请勿转载。