PHP uses Imagick to generate images, _php tutorials

Source: Internet
Author: User
Tags transparent color

PHP uses Imagick to generate pictures,


This example describes how PHP uses Imagick to generate images. Share to everyone for your reference. Specific as follows:

Use Imagick to generate images here
Solve the problem of writing Chinese characters garbled in pictures, add supported fonts

Public Function Getpic () {header (' content-type:text/html; Charset=utf-8 ');  $text = ' Cofco River (sh600737) ';//Cofco (sh600737) $watermark = ' 305988103123zczcxzas ';  $len = strlen ($text);  $width = 10.5* (($len-8)/3*2+8);  $height = 26;  $imagick = new Imagick (); $color _transparent = new Imagickpixel (' #ffffff ');  Transparent transparent color $imagick->newimage ($width, $height, $color _transparent, ' jpg ');  $imagick->borderimage (' #000000 ', 1, 1);  $style [' font_size '] = 12;  $style [' fill_color '] = ' #000000 '; for ($num = strlen ($watermark), $num >=0; $num-) {$this->add_text ($imagick, substr ($watermark, $num, 1), ($num *8   ), 1, $style);  $this->add_text ($imagick, substr ($watermark, $num, 1), ($num *8), 5, 1, $style);  }//return;  $style [' font_size '] = 20;  $style [' fill_color '] = ' #FF0000 '; $style [' font '] = './msyh.ttf '; Microsoft ya Black font to solve the Chinese garbled//$text =mb_convert_encoding ($text, ' UTF-8 ');  Iconv ("GBK", "Utf-8//ignore", $text);  $this->add_text ($imagick, $text, 2, 0, $style); Header (' ConteNt-type: '.  Strtolower ($imagick->getimageformat ())); echo $imagick->getimagesblob ();} Add watermark Text Public function Add_text (& $imagick, $text, $x = 0, $y = 0, $angle = 0, $style = Array ()) {$draw = new Imag  Ickdraw ();  if (Isset ($style [' font ')]) $draw->setfont ($style [' font ']);  if (Isset ($style [' font_size '])) $draw->setfontsize ($style [' font_size ']);  if (Isset ($style [' Fill_color '])) $draw->setfillcolor ($style [' Fill_color ']);  if (Isset ($style [' Under_color '])) $draw->settextundercolor ($style [' Under_color ']);  if (Isset ($style [' font_family '])) $draw->setfontfamily ($style [' font_family ']);  if (Isset ($style [' font ')]) $draw->setfont ($style [' font ']);  $draw->settextencoding (' UTF-8 ');  if (Strtolower ($imagick->getimageformat ()) = = ' gif ') {foreach ($imagick as $frame) {$frame->annotateimage   ($draw, $x, $y, $angle, $text); }} else {$imagick->annotateimage ($draw, $x, $y, $angLe, $text); }}

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/1041328.html www.bkjia.com true http://www.bkjia.com/PHPjc/1041328.html techarticle PHP uses Imagick to generate images, and this article explains how PHP uses Imagick to generate images. Share to everyone for your reference. Here are the following: Use Imagick to generate images ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.