最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

php使用Imagick生成圖片的方法

 更新時(shí)間:2015年07月31日 14:57:57   作者:龍sky騰  
這篇文章主要介紹了php使用Imagick生成圖片的方法,實(shí)例分析了php基于Imagick實(shí)現(xiàn)添加水印、文字的圖片功能,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了php使用Imagick生成圖片的方法。分享給大家供大家參考。具體如下:

這里使用Imagick 生成圖片
解決了圖片寫中文文字亂碼問題,添加支持的字體

public function getPic(){
  header('Content-Type: text/html; charset=utf-8');
  $text = '中糧屯河(sh600737)';//中糧屯河(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 透明色
  $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, 1,$style);
   $this->add_text($imagick,substr($watermark, $num,1), 2+($num*8), 5, 1,$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, 0,$style);
  header ( 'Content-type: ' . strtolower ($imagick->getImageFormat ()) );
  echo $imagick->getImagesBlob ();
}
// 添加水印文字
public function add_text(& $imagick, $text, $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, $x, $y, $angle, $text );
  }
}

希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

当阳市| 分宜县| 台中县| 靖州| 社会| 崇义县| 兴安县| 石棉县| 崇礼县| 多伦县| 南陵县| 安陆市| 邹平县| 东山县| 珲春市| 龙岩市| 吴桥县| 龙陵县| 松江区| 湟中县| 临清市| 甘德县| 威海市| 桃园县| 醴陵市| 扶余县| 平顶山市| 罗源县| 莫力| 霍山县| 盐源县| 竹北市| 平泉县| 依安县| 古田县| 冷水江市| 讷河市| 崇仁县| 六枝特区| 锡林浩特市| 确山县|