本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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";