php使用Imagick生成图片的方法

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了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使用Imagick生成图片的方法全部内容,希望文章能够帮你解决php使用Imagick生成图片的方法所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。