本文整理匯總了PHP中Imagick::annotateImage方法的典型用法代碼示例。如果您正苦於以下問題:PHP Imagick::annotateImage方法的具體用法?PHP Imagick::annotateImage怎麽用?PHP Imagick::annotateImage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Imagick
的用法示例。
在下文中一共展示了Imagick::annotateImage方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: createEmailPic
function createEmailPic($jid, $email)
{
$cachefile = DOCUMENT_ROOT . '/cache/' . $jid . '_email.png';
if (file_exists(DOCUMENT_ROOT . '/cache/' . $jid . '_email.png')) {
unlink(DOCUMENT_ROOT . '/cache/' . $jid . '_email.png');
}
$draw = new ImagickDraw();
$draw->setFontSize(13);
$draw->setGravity(Imagick::GRAVITY_CENTER);
$canvas = new Imagick();
$metrics = $canvas->queryFontMetrics($draw, $email);
$canvas->newImage($metrics['textWidth'], $metrics['textHeight'], "transparent", "png");
$canvas->annotateImage($draw, 0, 0, 0, $email);
$canvas->setImageFormat('PNG');
$canvas->writeImage($cachefile);
}
示例2: Imagick
function page_testfonts()
{
//load background
$im = new Imagick();
$im->newimage(800, 10000, 'lightgray');
$y = 10;
$i = 1;
foreach ($im->queryFonts() as $font) {
$insert_image = new Imagick();
$insert_image->newImage(600, 30, 'whitesmoke');
$insert_image->setImageFormat("png");
$draw = new ImagickDraw();
$draw->setFont($font);
$draw->setFontSize(25);
$draw->setFillColor(new ImagickPixel('black'));
$draw->setgravity(imagick::GRAVITY_NORTH);
$insert_image->annotateImage($draw, 0, 0, 0, $i . '.' . $font);
$im->compositeImage($insert_image, $insert_image->getImageCompose(), 100, $y);
$y += 30;
$i++;
}
$im->setImageFormat('jpg');
header('Content-Type: image/jpg');
echo $im;
}
示例3: text
/**
* Draws a text string on the image in a specified location, with the
* specified style information.
*
* @TODO: Need to differentiate between the stroke (border) and the fill
* color, but this is a BC break, since we were just not providing a
* border.
*
* @param string $text The text to draw.
* @param integer $x The left x coordinate of the start of the
* text string.
* @param integer $y The top y coordinate of the start of the text
* string.
* @param string $font The font identifier you want to use for the
* text.
* @param string $color The color that you want the text displayed in.
* @param integer $direction An integer that specifies the orientation of
* the text.
* @param string $fontsize Size of the font (small, medium, large, giant)
*/
public function text($string, $x, $y, $font = '', $color = 'black', $direction = 0, $fontsize = 'small')
{
$fontsize = Horde_Image::getFontSize($fontsize);
try {
$pixel = new ImagickPixel($color);
} catch (ImagickPixelException $e) {
throw new Horde_Image_Exception($e);
}
try {
$draw = new ImagickDraw();
$draw->setFillColor($pixel);
if (!empty($font)) {
$draw->setFont($font);
}
$draw->setFontSize($fontsize);
$draw->setGravity(Imagick::GRAVITY_NORTHWEST);
} catch (ImagickDrawException $e) {
throw new Horde_Image_Exception($e);
}
try {
$this->_imagick->annotateImage($draw, $x, $y, $direction, $string);
} catch (ImagickException $e) {
throw new Horde_Image_Exception($e);
}
$draw->destroy();
}
示例4: text
/**
* (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 \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);
}
}
示例5: drawText
protected function drawText($text, $size, $fontFile, $x, $y, $color, $opacity, $angle)
{
$draw = new $this->drawClass();
$draw->setFont($fontFile);
$draw->setFontSize($size);
$draw->setFillColor($this->getColor($color, $opacity));
$this->image->annotateImage($draw, $x, $y, -$angle, $text);
return $this;
}
示例6: 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
// );
$deltaX = $info['characterWidth'] * sin(deg2rad($angle));
$deltaY = $info['characterHeight'];
$posX = $position->getX() - $deltaX;
if ($posX < 0) {
$posX = 0;
}
$this->imagick->annotateImage($text, $posX, $position->getY() + $deltaY, $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;
}
示例7: generate
/**
* Generates and dies with an image containing the heading and the text of the error.
*
* @param string $headingText The heading of the error.
* @param string $errorText The text of the error.
*/
public function generate($headingText, $errorText)
{
$draw = new ImagickDraw();
$draw->setFillColor('#777777');
$draw->setFontSize(15);
$draw->setFont('fonts/exo2bold.ttf');
$headingMetrics = $this->canvas->queryFontMetrics($draw, $headingText);
$draw->setFont('fonts/exo2regular.ttf');
$textMetrics = $this->canvas->queryFontMetrics($draw, $errorText);
$this->canvas->newImage(max($textMetrics['textWidth'], $headingMetrics['textWidth']) + 6, $textMetrics['textHeight'] + $headingMetrics['textHeight'] + 6, new ImagickPixel('white'));
$this->canvas->annotateImage($draw, 3, $headingMetrics['textHeight'] * 2, 0, $errorText);
$draw->setFont('fonts/exo2bold.ttf');
$draw->setFillColor('#333333');
$draw->setGravity(Imagick::GRAVITY_NORTH);
$this->canvas->annotateImage($draw, 3, 3, 0, $headingText);
$this->canvas->setImageFormat('png');
header('Content-Type: image/' . $this->canvas->getImageFormat());
header("Cache-Control: max-age=60");
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 60) . " GMT");
die($this->canvas);
}
示例8: text
/**
* Execute a text
*
* @param string $text
* @param int $offsetX
* @param int $offsetY
* @param float $opacity
* @param int $color
* @param int $size
* @param string $font_file
*
* @return static
*/
public function text($text, $offsetX = 0, $offsetY = 0, $opacity = 1.0, $color = 0x0, $size = 12, $font_file = null)
{
$draw = new \ImagickDraw();
$textColor = sprintf('rgb(%u,%u,%u)', $color >> 16 & 0xff, $color >> 8 & 0xff, $color & 0xff);
$draw->setFillColor(new \ImagickPixel($textColor));
if ($font_file) {
$draw->setFont($this->alias->resolve($font_file));
}
$draw->setFontSize($size);
$draw->setFillOpacity($opacity);
$draw->setGravity(\Imagick::GRAVITY_NORTHWEST);
$this->_image->annotateImage($draw, $offsetX, $offsetY, 0, $text);
$draw->destroy();
return $this;
}
示例9: AboveText
function AboveText()
{
$abovetextimage = new Imagick();
$draw = new ImagickDraw();
$pixel = new ImagickPixel('transparent');
$abovetextimage->newImage(600, 600, $pixel);
$draw->setFillColor('black');
$draw->setFont('Bookman-DemiItalic');
$draw->setFontSize(20);
$myfirstName = explode(" ", $this->{$userName});
$fname = $myfirstName[0];
$abovetextimage->annotateImage($draw, 5, 20, 0, "{$this}->{$name} has a secret crush on {$fname}");
$abovetextimage->setImageFormat('png');
$abovetextimage->writeImage("abovetext.png");
$this->{$aboveText} = imagecreatefrompng("abovetext.png");
}
示例10: draw_text
protected function draw_text($text, $size, $font_file, $x, $y, $color, $opacity, $angle)
{
$draw = new $this->draw_class();
$draw->setFont($font_file);
$draw->setFontSize($size);
$draw->setFillColor($this->get_color($color, $opacity));
if ($this->multiframe()) {
$this->image = $this->image->coalesceImages();
foreach ($this->image as $frame) {
$frame->annotateImage($draw, $x, $y, -$angle, $text);
}
} else {
$this->image->annotateImage($draw, $x, $y, -$angle, $text);
}
return $this;
}
示例11: copyrightImage
/**
* Generate and save the image with a copyright text at the bottom right corner
*
* @param string $text The copyright text
* @param int $fontSize OPTIONAL the copyright font size DEFAULT 22
* @param string $font OPTIONAL the copyright font DEFAULT "Verdana"
* @param string $position OPTIONAL the position to put copyright text DEFAULT "bottom-right" Possibles
* Values ("bottom-right", "bottom-left", "top-right", "top-left")
*/
public function copyrightImage(string $text, int $fontSize = 22, string $font = 'Verdana', string $position = 'bottom-right')
{
$draw = new \ImagickDraw();
$draw->setFontSize($fontSize);
$draw->setFont($font);
$draw->setFillColor('#ffffff');
$draw->setTextUnderColor('#00000088');
$textMetrics = $this->image->queryFontMetrics($draw, $text);
$textWidth = $textMetrics['textWidth'] + 2 * $textMetrics['boundingBox']['x1'];
$extraTextHeight = $textMetrics['descender'];
$textHeight = $textMetrics['textHeight'] + $extraTextHeight;
switch ($position) {
case 'bottom-right':
$width = $this->image->getImageWidth() - $textWidth;
$height = $this->image->getImageHeight() + $extraTextHeight;
$width -= static::$EXTRA_TEXT_PADDING;
$height -= static::$EXTRA_TEXT_PADDING;
break;
case 'bottom-left':
$width = 0;
$height = $this->image->getImageHeight() + $extraTextHeight;
$width += static::$EXTRA_TEXT_PADDING;
$height -= static::$EXTRA_TEXT_PADDING;
break;
case 'top-right':
$width = $this->image->getImageWidth() - $textWidth;
$height = $textHeight;
$width -= static::$EXTRA_TEXT_PADDING;
$height += static::$EXTRA_TEXT_PADDING;
break;
case 'top-left':
$width = 0;
$height = $textHeight;
$width += static::$EXTRA_TEXT_PADDING;
$height += static::$EXTRA_TEXT_PADDING;
break;
default:
$width = $this->image->getImageWidth() - $textWidth;
$height = $this->image->getImageHeight() + $extraTextHeight;
$width -= static::$EXTRA_TEXT_PADDING;
$height -= static::$EXTRA_TEXT_PADDING;
break;
}
$this->image->annotateImage($draw, $width, $height, 0, $text);
$this->image->writeImage($this->imageSavePath . DIRECTORY_SEPARATOR . $this->imageName . '_copyright' . '.' . $this->imageExtension);
}
示例12: _watermark
/**
* @param array $options
* 'watermark' => waImage|string $watermark
* 'opacity' => float|int 0..1
* 'align' => self::ALIGN_* const
* 'font_file' => null|string If null - will be used some default font. Note: use when watermark option is text
* 'font_size' => float Size of font. Note: use when watermark option is text
* 'font_color' => string Hex-formatted of color (without #). Note: use when watermark option is text
* 'text_orientation' => self::ORIENTATION_* const. Note: use when watermark option is text
* @return mixed
*/
protected function _watermark($options)
{
// export options to php-vars
foreach ($options as $name => $value) {
${$name} = $value;
}
$opacity = min(max($opacity, 0), 1);
/**
* @var waImage $watermark
*/
if ($watermark instanceof waImage) {
$offset = $this->calcWatermarkOffset($watermark->width, $watermark->height, $align);
$watermark = new Imagick($watermark->file);
$watermark->evaluateImage(Imagick::EVALUATE_MULTIPLY, $opacity, Imagick::CHANNEL_ALPHA);
$this->im->compositeImage($watermark, Imagick::COMPOSITE_DEFAULT, $offset[0], $offset[1]);
$watermark->clear();
$watermark->destroy();
} else {
$text = (string) $watermark;
if (!$text) {
return;
}
$font_size = 24 * $font_size / 18;
// 24px = 18pt
$font_color = new ImagickPixel('#' . $font_color);
$watermark = new ImagickDraw();
$watermark->setFillColor($font_color);
$watermark->setFillOpacity($opacity);
if ($font_file && file_exists($font_file)) {
$watermark->setFont($font_file);
}
$watermark->setFontSize($font_size);
// Throws ImagickException on error
$metrics = $this->im->queryFontMetrics($watermark, $text);
$width = $metrics['textWidth'];
$height = $metrics['textHeight'];
if ($text_orientation == self::ORIENTATION_VERTICAL) {
list($width, $height) = array($height, $width);
}
$offset = $this->calcWatermarkTextOffset($width, $height, $align, $text_orientation);
$this->im->annotateImage($watermark, $offset[0], $offset[1], $text_orientation == self::ORIENTATION_VERTICAL ? -90 : 0, $text);
$watermark->clear();
$watermark->destroy();
}
}
示例13: TextOverlay
function TextOverlay()
{
$textimage = new Imagick();
$draw = new ImagickDraw();
$pixel = new ImagickPixel('transparent');
/* New image */
$textimage->newImage(600, 600, $pixel);
/* Black text */
$draw->setFillColor('blue');
/* Font properties */
$draw->setFont('Bookman-DemiItalic');
$draw->setFontSize(20);
/* Create text */
$textimage->annotateImage($draw, 5, 20, 0, "{$name} has a secret CRUSH on YOU!");
/* Give image a format */
$textimage->setImageFormat('png');
$textimage->writeImage("rounded3.png");
$top_image3 = imagecreatefrompng("rounded3.png");
}
示例14: fl_text_render
function fl_text_render($_file, $id, $text, $fontname, $fontsize, $color = "#000000", $out_image_file_type = "png")
{
$font = locate_font($fontname);
if ($font === false) {
fllog('fl_text_render: font `' . $fontname . '` not found at `' . flvault . $fontname . '`');
return false;
}
$render = false;
$out_image_file_type = strtolower($out_image_file_type);
$cachefile = flcache . $id . '.' . $out_image_file_type;
if ($_file !== false) {
if (file1_is_older($cachefile, $_file)) {
$render = true;
}
} else {
$render = true;
}
if ($render === true) {
try {
$draw = new ImagickDraw();
$draw->setFont($font);
$draw->setFontSize(intval($fontsize));
$draw->setGravity(Imagick::GRAVITY_CENTER);
$draw->setFillColor($color);
$canvas = new Imagick();
$m = $canvas->queryFontMetrics($draw, htmlspecialchars_decode($text));
$canvas->newImage($m['textWidth'], $m['textHeight'], "transparent", $out_image_file_type);
$canvas->annotateImage($draw, 0, 0, 0, $text);
$canvas->setImageFormat(strtoupper($out_image_file_type));
$canvas->writeImage($cachefile);
fllog('Writing to: ' . $cachefile);
$canvas->clear();
$canvas->destroy();
$draw->clear();
$draw->destroy();
} catch (Exception $e) {
fllog('fl_text_render() Error: ', $e->getMessage());
return false;
}
}
return $cachefile;
}
示例15: mkCapcha
/**
* Creates image with text
* @param int $sizeX
* @param int $sizeY
* @param string $text
* @param string $generator
* @return \Imagick
*/
public function mkCapcha($sizeX, $sizeY, $text, $generator = self::METHOD_DEFAULT)
{
// init image
$image = new \Imagick();
$image->newImage($sizeX, $sizeY, new \ImagickPixel('white'));
$image->setImageFormat('png');
switch ($generator) {
case self::METHOD_GRAYNOISE:
$draw = new \ImagickDraw();
$draw->setFontSize(35);
$draw->setFontWeight(900);
$draw->setGravity(\imagick::GRAVITY_CENTER);
$image->addNoiseImage(\imagick::NOISE_LAPLACIAN);
$image->annotateImage($draw, 0, 0, 0, $text);
$image->charcoalImage(2, 1.5);
$image->addNoiseImage(\imagick::NOISE_LAPLACIAN);
$image->gaussianBlurImage(1, 1);
break;
case self::METHOD_GRAYBLUR:
$draw = new \ImagickDraw();
$order = [];
for ($i = 0; $i < strlen($text); $i++) {
$order[$i] = $i;
}
shuffle($order);
for ($j = 0; $j < 2; $j++) {
shuffle($order);
$image->gaussianBlurImage(15, 3);
for ($n = 0; $n < strlen($text); $n++) {
$i = $order[$n];
$draw->setFont(__DIR__ . '/Capcha/DejaVuSans.ttf');
$draw->setFontSize($j ? rand($sizeY * 3 / 5, $sizeY * 5 / 6) : rand($sizeY * 4 / 6, $sizeY * 5 / 6));
$draw->setFontWeight(rand(100, 900));
$draw->setGravity(\imagick::GRAVITY_CENTER);
$image->annotateImage($draw, ($i - strlen($text) / 2) * $sizeX / (strlen($text) + 2.3), 0, rand(-25, 25), $text[$i]);
$image->gaussianBlurImage(1, 1);
}
}
break;
}
return $image;
}