示例#1
20
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
0
 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();
 }
示例#3
0
 /**
  * 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;
 }
示例#4
0
 /**
  * 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;
     }
 }
示例#5
0
文件: Captcha.php 项目: xepan/base
 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);
 }
示例#6
0
 /**
  * アバター自動生成処理
  *
  * @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;
 }
示例#7
0
文件: fonts.php 项目: xepan/commerce
 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;
 }
示例#8
0
 function writeText($text)
 {
     if ($this->printer == null) {
         throw new LogicException("Not attached to a printer.");
     }
     if ($text == null) {
         return;
     }
     $text = trim($text, "\n");
     /* Create Imagick objects */
     $image = new \Imagick();
     $draw = new \ImagickDraw();
     $color = new \ImagickPixel('#000000');
     $background = new \ImagickPixel('white');
     /* Create annotation */
     //$draw -> setFont('Arial');// (not necessary?)
     $draw->setFontSize(24);
     // Size 21 looks good for FONT B
     $draw->setFillColor($color);
     $draw->setStrokeAntialias(true);
     $draw->setTextAntialias(true);
     $metrics = $image->queryFontMetrics($draw, $text);
     $draw->annotation(0, $metrics['ascender'], $text);
     /* Create image & draw annotation on it */
     $image->newImage($metrics['textWidth'], $metrics['textHeight'], $background);
     $image->setImageFormat('png');
     $image->drawImage($draw);
     //$image -> writeImage("test.png");
     /* Save image */
     $escposImage = new EscposImage();
     $escposImage->readImageFromImagick($image);
     $size = Printer::IMG_DEFAULT;
     $this->printer->bitImage($escposImage, $size);
 }
示例#9
0
 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");
 }
示例#10
0
 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);
 }
示例#11
0
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);
}
示例#12
0
 /**
  * @param \Imagick $imagick
  * @param int $graphWidth
  * @param int $graphHeight
  */
 public static function analyzeImage(\Imagick $imagick, $graphWidth = 255, $graphHeight = 127)
 {
     $sampleHeight = 20;
     $border = 2;
     $imagick->transposeImage();
     $imagick->scaleImage($graphWidth, $sampleHeight);
     $imageIterator = new \ImagickPixelIterator($imagick);
     $luminosityArray = [];
     foreach ($imageIterator as $row => $pixels) {
         /* Loop through pixel rows */
         foreach ($pixels as $column => $pixel) {
             /* Loop through the pixels in the row (columns) */
             /** @var $pixel \ImagickPixel */
             if (false) {
                 $color = $pixel->getColor();
                 $luminosityArray[] = $color['r'];
             } else {
                 $hsl = $pixel->getHSL();
                 $luminosityArray[] = $hsl['luminosity'];
             }
         }
         /* Sync the iterator, this is important to do on each iteration */
         $imageIterator->syncIterator();
         break;
     }
     $draw = new \ImagickDraw();
     $strokeColor = new \ImagickPixel('red');
     $fillColor = new \ImagickPixel('red');
     $draw->setStrokeColor($strokeColor);
     $draw->setFillColor($fillColor);
     $draw->setStrokeWidth(0);
     $draw->setFontSize(72);
     $draw->setStrokeAntiAlias(true);
     $previous = false;
     $x = 0;
     foreach ($luminosityArray as $luminosity) {
         $pos = $graphHeight - 1 - $luminosity * ($graphHeight - 1);
         if ($previous !== false) {
             /** @var $previous int */
             //printf ( "%d, %d, %d, %d <br/>\n" , $x - 1, $previous, $x, $pos);
             $draw->line($x - 1, $previous, $x, $pos);
         }
         $x += 1;
         $previous = $pos;
     }
     $plot = new \Imagick();
     $plot->newImage($graphWidth, $graphHeight, 'white');
     $plot->drawImage($draw);
     $outputImage = new \Imagick();
     $outputImage->newImage($graphWidth, $graphHeight + $sampleHeight, 'white');
     $outputImage->compositeimage($plot, \Imagick::COMPOSITE_ATOP, 0, 0);
     $outputImage->compositeimage($imagick, \Imagick::COMPOSITE_ATOP, 0, $graphHeight);
     $outputImage->borderimage('black', $border, $border);
     $outputImage->setImageFormat("png");
     App::cachingHeader("Content-Type: image/png");
     echo $outputImage;
 }
示例#13
0
 /**
  * (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;
 }
示例#14
0
 /**
  * {@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;
 }
 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);
 }
示例#16
0
 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;
 }
示例#17
0
 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"));
     //        $compositeModes = [
     //
     //            \Imagick::COMPOSITE_NO, \Imagick::COMPOSITE_ADD, \Imagick::COMPOSITE_ATOP, \Imagick::COMPOSITE_BLEND, \Imagick::COMPOSITE_BUMPMAP, \Imagick::COMPOSITE_CLEAR, \Imagick::COMPOSITE_COLORBURN, \Imagick::COMPOSITE_COLORDODGE, \Imagick::COMPOSITE_COLORIZE, \Imagick::COMPOSITE_COPYBLACK, \Imagick::COMPOSITE_COPYBLUE, \Imagick::COMPOSITE_COPY, \Imagick::COMPOSITE_COPYCYAN, \Imagick::COMPOSITE_COPYGREEN, \Imagick::COMPOSITE_COPYMAGENTA, \Imagick::COMPOSITE_COPYOPACITY, \Imagick::COMPOSITE_COPYRED, \Imagick::COMPOSITE_COPYYELLOW, \Imagick::COMPOSITE_DARKEN, \Imagick::COMPOSITE_DSTATOP, \Imagick::COMPOSITE_DST, \Imagick::COMPOSITE_DSTIN, \Imagick::COMPOSITE_DSTOUT, \Imagick::COMPOSITE_DSTOVER, \Imagick::COMPOSITE_DIFFERENCE, \Imagick::COMPOSITE_DISPLACE, \Imagick::COMPOSITE_DISSOLVE, \Imagick::COMPOSITE_EXCLUSION, \Imagick::COMPOSITE_HARDLIGHT, \Imagick::COMPOSITE_HUE, \Imagick::COMPOSITE_IN, \Imagick::COMPOSITE_LIGHTEN, \Imagick::COMPOSITE_LUMINIZE, \Imagick::COMPOSITE_MINUS, \Imagick::COMPOSITE_MODULATE, \Imagick::COMPOSITE_MULTIPLY, \Imagick::COMPOSITE_OUT, \Imagick::COMPOSITE_OVER, \Imagick::COMPOSITE_OVERLAY, \Imagick::COMPOSITE_PLUS, \Imagick::COMPOSITE_REPLACE, \Imagick::COMPOSITE_SATURATE, \Imagick::COMPOSITE_SCREEN, \Imagick::COMPOSITE_SOFTLIGHT, \Imagick::COMPOSITE_SRCATOP, \Imagick::COMPOSITE_SRC, \Imagick::COMPOSITE_SRCIN, \Imagick::COMPOSITE_SRCOUT, \Imagick::COMPOSITE_SRCOVER, \Imagick::COMPOSITE_SUBTRACT, \Imagick::COMPOSITE_THRESHOLD, \Imagick::COMPOSITE_XOR,
     //
     //        ];
     $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();
 }
示例#18
0
 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");
 }
示例#19
0
文件: Font.php 项目: hilmysyarif/sic
 /**
  * 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);
 }
示例#20
0
 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;
 }
示例#21
0
function a0nCRQ($msg, $padx, $pady, $bc, $fc, $tc)
{
    $im = new Imagick();
    $idraw = new ImagickDraw();
    $idraw->setFontSize(30);
    $idraw->setFont('MyriadPro-Regular.otf');
    $idraw->setGravity(Imagick::GRAVITY_CENTER);
    $metrics = $im->queryFontMetrics($idraw, $msg);
    $im->newPseudoImage($metrics["textWidth"] + $padx * 2, $metrics["textHeight"] + $pady * 2, "xc:none");
    $idraw->setFillColor($fc);
    $idraw->setStrokeColor($bc);
    $idraw->roundrectangle(0, 0, $metrics["textWidth"] + $padx * 2 - 1, $metrics["textHeight"] + $pady * 2 - 1, 10, 10);
    $idraw->setFillColor($tc);
    $idraw->setStrokeColor($tc);
    $idraw->annotation(0, 0, $msg);
    $im->drawImage($idraw);
    return $im;
}
示例#22
0
 public function render($pDatas)
 {
     $im = new Imagick();
     $im->newImage(300, 300, "white", "png");
     $draw = new ImagickDraw();
     foreach ($pDatas as $key => $data) {
         if ($data->value == 0) {
             continue;
         }
         $draw->setFillColor('red');
         $draw->setstrokecolor('black');
         $draw->polygon($data->polygons);
         $draw->setFillColor('black');
         $draw->setFontSize(18);
         $draw->annotation($data->center['x'], $data->center['y'] + 9, $data->value);
     }
     $im->drawimage($draw);
     return $im;
 }
示例#23
0
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");
}
示例#24
0
文件: Render.php 项目: h3rb/page
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;
}
示例#25
0
 protected function _generateImage($text, $filePath)
 {
     $image = new Imagick();
     $draw = new ImagickDraw();
     $draw->setFont('lib/SwiftOtter/OpenSans-Regular.ttf');
     $draw->setFontSize('13');
     $metrics = $image->queryFontMetrics($draw, $text, false);
     $width = 100;
     $padding = 10;
     if (isset($metrics['textWidth'])) {
         $width = $metrics['textWidth'] + $padding * 2;
     }
     $image->newImage($width, 17, new ImagickPixel('#f98b25'));
     $draw->setFillColor('#ffffff');
     $image->annotateImage($draw, $padding / 2 + 3, $padding + 3, 0, $text);
     $draw->setFillColor('#a04300');
     $image->borderImage('#a04300', 1, 1);
     $image->setFormat('gif');
     $image->writeImage($filePath);
     return $image;
 }
示例#26
0
 /**
  * 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);
 }
示例#27
0
function drawText(\Imagick $imagick, $shadow = false)
{
    $draw = new \ImagickDraw();
    if ($shadow == true) {
        $draw->setStrokeColor('black');
        $draw->setStrokeWidth(8);
        $draw->setFillColor('black');
    } else {
        $draw->setStrokeColor('none');
        $draw->setStrokeWidth(1);
        $draw->setFillColor('lightblue');
    }
    $draw->setFontSize(96);
    $text = "Imagick\nExample";
    $draw->setFont("../fonts/CANDY.TTF");
    $draw->setGravity(\Imagick::GRAVITY_SOUTHWEST);
    $imagick->annotateimage($draw, 40, 40, 0, $text);
    if ($shadow == true) {
        $imagick->blurImage(10, 5);
    }
    return $imagick;
}
示例#28
0
 public function renderImage()
 {
     $imagick = new \Imagick(realpath("images/TestImage.jpg"));
     $draw = new \ImagickDraw();
     $darkColor = new \ImagickPixel('brown');
     $lightColor = new \ImagickPixel('LightCoral');
     $draw->setStrokeColor($darkColor);
     $draw->setFillColor($lightColor);
     $draw->setStrokeWidth(2);
     $draw->setFontSize(36);
     $draw->setFont("../fonts/Arial.ttf");
     $draw->annotation(50, 50, "Lorem Ipsum!");
     $msg = "Danack";
     $xpos = 0;
     $ypos = 0;
     list($lines, $lineHeight) = wordWrapAnnotation($imagick, $draw, $msg, 140);
     for ($i = 0; $i < count($lines); $i++) {
         $imagick->annotateImage($draw, $xpos, $ypos + $i * $lineHeight, 0, $lines[$i]);
     }
     header("Content-Type: image/jpg");
     echo $imagick->getImageBlob();
 }
示例#29
0
 public function stage()
 {
     $this->init();
     $this->background();
     $color = $this->font;
     $color = new \ImagickPixel(sprintf('rgba(%d, %d, %d, %.2f)', $color['r'], $color['g'], $color['b'], (100 - $this->config['opacity']) / 100));
     $text = new \ImagickDraw();
     $text->setFillColor($color);
     $text->setFont($this->config['font']);
     $size = 1;
     $text->setFontSize($size);
     $height = $this->options['size'] / 100 * $this->config['prop'];
     $metrics = $this->ivatar->queryFontMetrics($text, $this->text, false);
     while ($metrics['boundingBox']['y2'] - $metrics['boundingBox']['y1'] <= $height) {
         $size++;
         $text->setFontSize($size);
         $metrics = $this->ivatar->queryFontMetrics($text, $this->text, false);
     }
     $x = ($this->options['size'] - $metrics['textWidth']) / 2 + $this->config['offset']['x'] / 100 * $this->options['size'];
     $y = ($this->options['size'] - ($metrics['boundingBox']['y2'] - $metrics['boundingBox']['y1'])) / 2 + ($metrics['boundingBox']['y2'] - $metrics['boundingBox']['y1']) + $this->config['offset']['y'] / 100 * $this->options['size'];
     $this->ivatar->annotateImage($text, $x, $y, null, $this->text);
 }
示例#30
0
 public function writeText($text)
 {
     if ($this->printer == null) {
         throw new LogicException("Not attached to a printer.");
     }
     if ($text == null) {
         return;
     }
     $text = trim($text, "\n");
     /* Create Imagick objects */
     $image = new \Imagick();
     $draw = new \ImagickDraw();
     $color = new \ImagickPixel('#000000');
     $background = new \ImagickPixel('white');
     /* Create annotation */
     if ($this->font !== null) {
         // Allow fallback on defaults as necessary
         $draw->setFont($this->font);
     }
     /* In Arial, size 21 looks good as a substitute for FONT_B, 24 for FONT_A */
     $draw->setFontSize($this->fontSize);
     $draw->setFillColor($color);
     $draw->setStrokeAntialias(true);
     $draw->setTextAntialias(true);
     $metrics = $image->queryFontMetrics($draw, $text);
     $draw->annotation(0, $metrics['ascender'], $text);
     /* Create image & draw annotation on it */
     $image->newImage($metrics['textWidth'], $metrics['textHeight'], $background);
     $image->setImageFormat('png');
     $image->drawImage($draw);
     // debugging if you want to view the images yourself
     //$image -> writeImage("test.png");
     /* Save image */
     $escposImage = new ImagickEscposImage();
     $escposImage->readImageFromImagick($image);
     $size = Printer::IMG_DEFAULT;
     $this->printer->bitImage($escposImage, $size);
 }