php使用Imagick產生圖片的方法,_PHP教程

來源:互聯網
上載者:User

php使用Imagick產生圖片的方法,


本文執行個體講述了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 );  }}

希望本文所述對大家的php程式設計有所協助。

http://www.bkjia.com/PHPjc/1041328.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1041328.htmlTechArticlephp使用Imagick產生圖片的方法, 本文執行個體講述了php使用Imagick產生圖片的方法。分享給大家供大家參考。具體如下: 這裡使用Imagick 產生圖片...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.