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 ...