微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php使用Imagick生成图片的方法

本文实例讲述了PHP使用Imagick生成图片方法分享给大家供大家参考。具体如下:

这里使用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),2+($num*8),30,$style); $this->add_text($imagick,5,$style); } //return; $style['font_size'] = 20; $style['fill_color'] = '#FF0000'; $style['font'] = './msyh.ttf'; ///微软雅黑字体 解决中文乱码 //$text=mb_convert_encoding($text,'UTF-8'); //iconv("GBK","UTF-8//IGnorE",$text); $this->add_text($imagick,$text,2,20,$style); header ( 'Content-type: ' . strtolower ($imagick->getimageFormat ()) ); echo $imagick->getimagesBlob (); } // 添加水印文字 public function add_text(& $imagick,$x = 0,$y = 0,$angle = 0,$style = array()) { $draw = new ImagickDraw (); 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,$text ); } }

希望本文所述对大家的PHP程序设计有所帮助。

原文地址:https://www.jb51.cc/php/21351.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐