当前位置: 首页>>代码示例>>PHP>>正文


PHP ImagickDraw::setFont方法代码示例

本文整理汇总了PHP中ImagickDraw::setFont方法的典型用法代码示例。如果您正苦于以下问题:PHP ImagickDraw::setFont方法的具体用法?PHP ImagickDraw::setFont怎么用?PHP ImagickDraw::setFont使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ImagickDraw的用法示例。


在下文中一共展示了ImagickDraw::setFont方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: createAvatarAutomatically

 /**
  * アバター自動生成処理
  *
  * @param Model $model ビヘイビア呼び出し元モデル
  * @param array $user ユーザデータ配列
  * @return mixed On success Model::$data, false on failure
  * @throws InternalErrorException
  */
 public function createAvatarAutomatically(Model $model, $user)
 {
     //imagickdraw オブジェクトを作成します
     $draw = new ImagickDraw();
     //文字色のセット
     $draw->setfillcolor('white');
     //フォントサイズを 160 に設定します
     $draw->setFontSize(140);
     //テキストを追加します
     $draw->setFont(CakePlugin::path($model->plugin) . 'webroot' . DS . 'fonts' . DS . 'ipaexg.ttf');
     $draw->annotation(19, 143, mb_substr(mb_convert_kana($user['User']['handlename'], 'KVA'), 0, 1));
     //新しいキャンバスオブジェクトを作成する
     $canvas = new Imagick();
     //ランダムで背景色を指定する
     $red1 = strtolower(dechex(mt_rand(3, 12)));
     $red2 = strtolower(dechex(mt_rand(0, 15)));
     $green1 = strtolower(dechex(mt_rand(3, 12)));
     $green2 = strtolower(dechex(mt_rand(0, 15)));
     $blue1 = strtolower(dechex(mt_rand(3, 12)));
     $blue2 = strtolower(dechex(mt_rand(0, 15)));
     $canvas->newImage(179, 179, '#' . $red1 . $red2 . $green1 . $green2 . $blue1 . $blue2);
     //ImagickDraw をキャンバス上に描画します
     $canvas->drawImage($draw);
     //フォーマットを PNG に設定します
     $canvas->setImageFormat('png');
     App::uses('TemporaryFolder', 'Files.Utility');
     $folder = new TemporaryFolder();
     $filePath = $folder->path . DS . Security::hash($user['User']['handlename'], 'md5') . '.png';
     $canvas->writeImages($filePath, true);
     return $filePath;
 }
开发者ID:akagane99,项目名称:Users,代码行数:39,代码来源:AvatarBehavior.php

示例2: createImage

 private function createImage()
 {
     /* Create Imagick object */
     $this->Imagick = new \Imagick();
     /* Create the ImagickPixel object (used to set the background color on image) */
     $bg = new \ImagickPixel();
     /* Set the pixel color to white */
     $bg->setColor($this->bg_color);
     /* Create a drawing object and set the font size */
     $ImagickDraw = new \ImagickDraw();
     /* Set font and font size. You can also specify /path/to/font.ttf */
     if ($this->font) {
         $ImagickDraw->setFont($this->font);
     }
     $ImagickDraw->setFontSize($this->font_size);
     /* Create new empty image */
     $this->Imagick->newImage($this->image_width, $this->image_height, $bg);
     /* Write the text on the image */
     $this->Imagick->annotateImage($ImagickDraw, $this->text_position_left, $this->text_position_top, 0, $this->getCaptchaText());
     /* Add some swirl */
     $this->Imagick->swirlImage(20);
     /* Create a few random lines */
     $ImagickDraw->line(rand(0, $this->image_width), rand(0, $this->image_height), rand(0, $this->image_width), rand(0, $this->image_height));
     $ImagickDraw->line(rand(0, $this->image_width), rand(0, $this->image_height), rand(0, $this->image_width), rand(0, $this->image_height));
     $ImagickDraw->line(rand(0, $this->image_width), rand(0, $this->image_height), rand(0, $this->image_width), rand(0, $this->image_height));
     $ImagickDraw->line(rand(0, $this->image_width), rand(0, $this->image_height), rand(0, $this->image_width), rand(0, $this->image_height));
     $ImagickDraw->line(rand(0, $this->image_width), rand(0, $this->image_height), rand(0, $this->image_width), rand(0, $this->image_height));
     /* Draw the ImagickDraw object contents to the image. */
     $this->Imagick->drawImage($ImagickDraw);
     /* Give the image a format */
     $this->Imagick->setImageFormat($this->image_format);
 }
开发者ID:xepan,项目名称:base,代码行数:32,代码来源:Captcha.php

示例3: renderImage

 public function renderImage()
 {
     //Create a ImagickDraw object to draw into.
     $draw = new \ImagickDraw();
     $darkColor = new \ImagickPixel('brown');
     //http://www.imagemagick.org/Usage/compose/#compose_terms
     $draw->setStrokeColor($darkColor);
     $draw->setFillColor('white');
     $draw->setStrokeWidth(2);
     $draw->setFontSize(72);
     $draw->setStrokeOpacity(1);
     $draw->setStrokeColor($darkColor);
     $draw->setStrokeWidth(2);
     $draw->setFont("../fonts/CANDY.TTF");
     $draw->setFontSize(140);
     $draw->setFillColor('none');
     $draw->rectangle(0, 0, 1000, 300);
     $draw->setFillColor('white');
     $draw->annotation(50, 180, "Lorem Ipsum!");
     $imagick = new \Imagick(realpath("images/TestImage.jpg"));
     $draw->composite(\Imagick::COMPOSITE_MULTIPLY, -500, -200, 2000, 600, $imagick);
     //Create an image object which the draw commands can be rendered into
     $imagick = new \Imagick();
     $imagick->newImage(1000, 300, "SteelBlue2");
     $imagick->setImageFormat("png");
     //Render the draw commands in the ImagickDraw object
     //into the image.
     $imagick->drawImage($draw);
     //Send the image to the browser
     header("Content-Type: image/png");
     echo $imagick->getImageBlob();
 }
开发者ID:finelinePG,项目名称:imagick,代码行数:32,代码来源:compositeText.php

示例4: 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;
 }
开发者ID:xepan,项目名称:commerce,代码行数:25,代码来源:fonts.php

示例5: 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

示例6: __construct

 /**
  * Creates a new Label component.
  *
  * @param OsuSignature $signature The base signature
  * @param int $x The X position of this label
  * @param int $y The Y position of this label
  * @param string $text The text of this label
  * @param string $font The font to use for this label; can be a string or the constants defined in {@link ComponentLabel}
  * @param string $colour The colour of the text of the label
  * @param int $fontSize The size of the font of the label
  * @param int $textAlignment The text alignment
  * @param int $width Width of the label, set to -1 to use the text size, anything bigger can be used to spoof the component system. -2 makes the component sizeless
  * @param int $height Height of the label, set to -1 to use the text size, anything bigger can be used to spoof the component system
  */
 public function __construct(OsuSignature $signature, $x = 0, $y = 0, $text, $font = self::FONT_REGULAR, $colour = '#555555', $fontSize = 14, $textAlignment = Imagick::ALIGN_UNDEFINED, $width = -1, $height = -1)
 {
     parent::__construct($signature, $x, $y);
     $this->text = $text;
     $this->font = $font;
     $this->colour = $colour;
     $this->fontSize = $fontSize;
     $this->textAlignment = $textAlignment;
     $this->width = $width;
     $this->height = $height;
     $this->drawSettings = new ImagickDraw();
     $this->drawSettings->setFont(self::FONT_DIRECTORY . $font);
     $this->drawSettings->setFontSize($fontSize);
     $this->drawSettings->setTextAlignment($textAlignment);
     $this->drawSettings->setFillColor($colour);
     $this->usesSpace = $width != -2;
     if ($width <= -1 || $height <= -1) {
         $tempImg = new Imagick();
         $metrics = $tempImg->queryFontMetrics($this->drawSettings, $this->text);
         $this->width = $width <= -1 ? $metrics['textWidth'] : $width;
         // yeah i have to do some bullshit
         $this->actualWidth = $metrics['textWidth'];
         $this->height = $metrics['boundingBox']['y2'] - $this->y;
     }
 }
开发者ID:BTCTaras,项目名称:osusig,代码行数:39,代码来源:ComponentLabel.php

示例7: makeImageOfCertification

 public function makeImageOfCertification()
 {
     date_default_timezone_set('UTC');
     $timeStamp = date('jS F Y');
     $text = "CERTIFIED COPY" . "\n" . $this->serial . "\n" . $timeStamp;
     $image = new \Imagick();
     $draw = new \ImagickDraw();
     $color = new \ImagickPixel('#000000');
     $background = new \ImagickPixel("rgb(85, 196, 241)");
     $draw->setFont($this->container->getParameter('assetic.write_to') . $this->container->get('templating.helper.assets')->getUrl('fonts/futura.ttf'));
     $draw->setFontSize(24);
     $draw->setFillColor($color);
     $draw->setTextAntialias(true);
     $draw->setStrokeAntialias(true);
     //Align text to the center of the background
     $draw->setTextAlignment(\Imagick::ALIGN_CENTER);
     //Get information of annotation image
     $metrics = $image->queryFontMetrics($draw, $text);
     //Calc the distance(pixels) to move the sentences
     $move = $metrics['textWidth'] / 2;
     $draw->annotation($move, $metrics['ascender'], $text);
     //Create an image of certification
     $image->newImage($metrics['textWidth'], $metrics['textHeight'], $background);
     $image->setImageFormat('png');
     $image->drawImage($draw);
     //Save an image temporary
     $image->writeImage("cert_" . $this->serial . "_.png");
 }
开发者ID:DanieleMenara,项目名称:CreateSafe,代码行数:28,代码来源:WaterMark.php

示例8: box

 /**
  * (non-PHPdoc)
  * @see Imagine\Image\FontInterface::box()
  */
 public function box($string, $angle = 0)
 {
     $text = new \ImagickDraw();
     $text->setFont($this->file);
     $text->setFontSize($this->size);
     $info = $this->imagick->queryFontMetrics($text, $string);
     $box = new Box($info['textWidth'], $info['textHeight']);
     return $box;
 }
开发者ID:SerdarSanri,项目名称:laravel-imagine-bundle,代码行数:13,代码来源:Font.php

示例9: printText

 public function printText($canvas, $size, $angle, $x, $y, $color, $fontfile, $text, $opacity = 100)
 {
     $draw = new ImagickDraw();
     $draw->setFillColor(self::rgb($color));
     $draw->setFontSize($size * $this->fontSizeScale);
     $draw->setFont($fontfile);
     $draw->setFillOpacity($opacity / 100);
     $canvas->annotateImage($draw, $x, $y, $angle, $text);
 }
开发者ID:neilcrookes,项目名称:Ximi,代码行数:9,代码来源:ximi_image_imagick.php

示例10: test_annotation

function test_annotation(&$canvas)
{
    $draw = new ImagickDraw();
    $font = __DIR__ . '/php_imagick_tests/anonymous_pro_minus.ttf';
    $draw->setFont($font);
    $draw->setFontSize(40);
    $draw->annotation(50, 440, 'Yukkuri shiteitte ne!!!');
    $canvas->drawImage($draw);
}
开发者ID:badlamer,项目名称:hhvm,代码行数:9,代码来源:draw_example.php

示例11: render

 function render()
 {
     $text = "Lorem ipsum";
     $im = new \Imagick();
     $draw = new \ImagickDraw();
     $draw->setStrokeColor("none");
     $draw->setFont("../fonts/Arial.ttf");
     $draw->setFontSize(96);
     $draw->setTextAlignment(\Imagick::ALIGN_LEFT);
     $metrics = $im->queryFontMetrics($draw, $text);
     return print_table($metrics);
 }
开发者ID:sdmmember,项目名称:Imagick-demos,代码行数:12,代码来源:queryFontMetrics.php

示例12: getImagineImage

 public function getImagineImage(ImagineInterface $imagine, FontCollection $fontCollection, $width, $height)
 {
     $fontPath = $fontCollection->getFontById($this->font)->getPath();
     if ($this->getAbsoluteSize() !== null) {
         $fontSize = $this->getAbsoluteSize();
     } elseif ($this->getRelativeSize() !== null) {
         $fontSize = (int) $this->getRelativeSize() / 100 * $height;
     } else {
         throw new \LogicException('Either relative or absolute watermark size must be set!');
     }
     if (true || !class_exists('ImagickDraw')) {
         // Fall back to ugly image.
         $palette = new \Imagine\Image\Palette\RGB();
         $font = $imagine->font($fontPath, $fontSize, $palette->color('#000'));
         $box = $font->box($this->getText());
         $watermarkImage = $imagine->create($box, $palette->color('#FFF'));
         $watermarkImage->draw()->text($this->text, $font, new \Imagine\Image\Point(0, 0));
     } else {
         // CURRENTLY DISABLED.
         // Use nicer Imagick implementation.
         // Untested!
         // @todo Test and implement it!
         $draw = new \ImagickDraw();
         $draw->setFont($fontPath);
         $draw->setFontSize($fontSize);
         $draw->setStrokeAntialias(true);
         //try with and without
         $draw->setTextAntialias(true);
         //try with and without
         $draw->setFillColor('#fff');
         $textOnly = new \Imagick();
         $textOnly->newImage(1400, 400, "transparent");
         //transparent canvas
         $textOnly->annotateImage($draw, 0, 0, 0, $this->text);
         //Create stroke
         $draw->setFillColor('#000');
         //same as stroke color
         $draw->setStrokeColor('#000');
         $draw->setStrokeWidth(8);
         $strokeImage = new \Imagick();
         $strokeImage->newImage(1400, 400, "transparent");
         $strokeImage->annotateImage($draw, 0, 0, 0, $this->text);
         //Composite text over stroke
         $strokeImage->compositeImage($textOnly, \Imagick::COMPOSITE_OVER, 0, 0, \Imagick::CHANNEL_ALPHA);
         $strokeImage->trimImage(0);
         //cut transparent border
         $watermarkImage = $imagine->load($strokeImage->getImageBlob());
         //$strokeImage->resizeImage(300,0, \Imagick::FILTER_CATROM, 0.9, false); //resize to final size
     }
     return $watermarkImage;
 }
开发者ID:shefik,项目名称:MediaModule,代码行数:51,代码来源:TextWatermarkEntity.php

示例13: 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");
 }
开发者ID:shahwaiz90,项目名称:Secret-Crush,代码行数:16,代码来源:imageprocessing.php

示例14: applyToImage

 /**
  * Draws font to given image at given position
  *
  * @param  Image   $image
  * @param  integer $posx
  * @param  integer $posy
  * @return void
  */
 public function applyToImage(Image $image, $posx = 0, $posy = 0)
 {
     // build draw object
     $draw = new \ImagickDraw();
     $draw->setStrokeAntialias(true);
     $draw->setTextAntialias(true);
     // set font file
     if ($this->hasApplicableFontFile()) {
         $draw->setFont($this->file);
     } else {
         throw new \Intervention\Image\Exception\RuntimeException("Font file must be provided to apply text to image.");
     }
     // parse text color
     $color = new Color($this->color);
     $draw->setFontSize($this->size);
     $draw->setFillColor($color->getPixel());
     // align horizontal
     switch (strtolower($this->align)) {
         case 'center':
             $align = \Imagick::ALIGN_CENTER;
             break;
         case 'right':
             $align = \Imagick::ALIGN_RIGHT;
             break;
         default:
             $align = \Imagick::ALIGN_LEFT;
             break;
     }
     $draw->setTextAlignment($align);
     // align vertical
     if (strtolower($this->valign) != 'bottom') {
         // calculate box size
         $dimensions = $image->getCore()->queryFontMetrics($draw, $this->text);
         // corrections on y-position
         switch (strtolower($this->valign)) {
             case 'center':
             case 'middle':
                 $posy = $posy + $dimensions['textHeight'] * 0.65 / 2;
                 break;
             case 'top':
                 $posy = $posy + $dimensions['textHeight'] * 0.65;
                 break;
         }
     }
     // apply to image
     $image->getCore()->annotateImage($draw, $posx, $posy, $this->angle * -1, $this->text);
 }
开发者ID:hilmysyarif,项目名称:sic,代码行数:55,代码来源:Font.php

示例15: build

 public function build()
 {
     // Prepage image
     $this->_canvas = new Imagick();
     $this->_canvas->newImage(self::WIDTH, self::HEIGHT, new ImagickPixel("white"));
     $color['line'] = new ImagickPixel("rgb(216, 76, 64)");
     $color['text'] = new ImagickPixel("rgb(16, 35, 132)");
     $color['karma'] = new ImagickPixel("rgb(116, 194, 98)");
     $color['force'] = new ImagickPixel("rgb(37, 168, 255)");
     $color['bottom_bg'] = new ImagickPixel("rgb(255, 244, 224)");
     $color['bg'] = new ImagickPixel("white");
     $color['neutral'] = new ImagickPixel("rgb(200, 200, 200)");
     $color['habr'] = new ImagickPixel("rgb(83, 121, 139)");
     // Prepare canvas for drawing main graph
     $draw = new ImagickDraw();
     $draw->setStrokeAntialias(true);
     $draw->setStrokeWidth(2);
     // Prepare values for drawing main graph
     define('PADDING', 10);
     // Draw bottom bg
     define('TOP_SPACER', 10);
     $draw = new ImagickDraw();
     $draw->setFillColor($color['bg']);
     $draw->setStrokeColor($color['habr']);
     $draw->polyline(array(array('x' => 0, 'y' => 0), array('x' => self::WIDTH - 1, 'y' => 0), array('x' => self::WIDTH - 1, 'y' => self::HEIGHT - 1), array('x' => 0, 'y' => self::HEIGHT - 1), array('x' => 0, 'y' => 0)));
     $this->_canvas->drawImage($draw);
     $draw->destroy();
     // Draw texts
     $draw = new ImagickDraw();
     $draw->setTextAlignment(Imagick::ALIGN_CENTER);
     $draw->setTextAntialias(true);
     $draw->setFillColor($color['karma']);
     $draw->polyline(array(array('x' => 1, 'y' => 1), array('x' => self::WIDTH / 2, 'y' => 1), array('x' => self::WIDTH / 2, 'y' => self::HEIGHT - 2), array('x' => 1, 'y' => self::HEIGHT - 2), array('x' => 1, 'y' => 1)));
     $draw->setFillColor($color['bg']);
     $draw->setFontSize(11);
     $draw->setFont(realpath('stuff/consolab.ttf'));
     $draw->annotation(self::WIDTH / 4, 11, sprintf('%01.2f', $this->_karma));
     $draw->setFillColor($color['force']);
     $draw->polyline(array(array('x' => self::WIDTH / 2 + 1, 'y' => 1), array('x' => self::WIDTH - 2, 'y' => 1), array('x' => self::WIDTH - 2, 'y' => self::HEIGHT - 2), array('x' => self::WIDTH / 2 + 1, 'y' => self::HEIGHT - 2), array('x' => self::WIDTH / 2 + 1, 'y' => 1)));
     $draw->setFillColor($color['bg']);
     $draw->annotation(self::WIDTH / 4 * 3, 11, sprintf('%01.2f', $this->_habraforce));
     $this->_canvas->drawImage($draw);
     $draw->destroy();
     return true;
 }
开发者ID:lknight,项目名称:habrometr,代码行数:45,代码来源:88x15.php


注:本文中的ImagickDraw::setFont方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。