国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

php使用Imagick生成圖片的方法

2024-05-04 23:38:30
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了php使用Imagick生成圖片的方法,實例分析了php基于Imagick實現添加水印、文字的圖片功能,具有一定參考借鑒價值,需要的朋友可以參考下

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

這里使用Imagick 生成圖片

解決了圖片寫中文文字亂碼問題,添加支持的字體

 

 
  1. public function getPic(){ 
  2. header('Content-Type: text/html; charset=utf-8'); 
  3. $text = '中糧屯河(sh600737)';//中糧屯河(sh600737) 
  4. $watermark = '305988103123zczcxzas'
  5. $len = strlen($text); 
  6. $width = 10.5*(($len-8)/3*2+8); 
  7. $height = 26; 
  8. $imagick = new Imagick(); 
  9. $color_transparent = new ImagickPixel('#ffffff'); //transparent 透明色 
  10. $imagick->newImage($width$height$color_transparent'jpg'); 
  11. //$imagick->borderimage('#000000', 1, 1); 
  12. $style['font_size'] = 12; 
  13. $style['fill_color'] = '#000000'
  14. for($numstrlen($watermark); $num>=0; $num--){ 
  15. $this->add_text($imagick,substr($watermark$num,1), 2+($num*8), 30, 1,$style); 
  16. $this->add_text($imagick,substr($watermark$num,1), 2+($num*8), 5, 1,$style); 
  17. //return; 
  18. $style['font_size'] = 20; 
  19. $style['fill_color'] = '#FF0000'
  20. $style['font'] = './msyh.ttf'///微軟雅黑字體 解決中文亂碼 
  21. //$text=mb_convert_encoding($text,'UTF-8'); //iconv("GBK","UTF-8//IGNORE",$text); 
  22. $this->add_text($imagick,$text, 2, 20, 0,$style); 
  23. header ( 'Content-type: ' . strtolower ($imagick->getImageFormat ()) ); 
  24. echo $imagick->getImagesBlob (); 
  25. // 添加水印文字 
  26. public function add_text(& $imagick$text$x = 0, $y = 0, $angle = 0, $style = array()) { 
  27. $draw = new ImagickDraw (); 
  28. if (isset ( $style ['font'] )) 
  29. $draw->setFont ( $style ['font'] ); 
  30. if (isset ( $style ['font_size'] )) 
  31. $draw->setFontSize ( $style ['font_size'] ); 
  32. if (isset ( $style ['fill_color'] )) 
  33. $draw->setFillColor ( $style ['fill_color'] ); 
  34. if (isset ( $style ['under_color'] )) 
  35. $draw->setTextUnderColor ( $style ['under_color'] ); 
  36. if (isset ( $style ['font_family'] )) 
  37. $draw->setfontfamily( $style ['font_family'] ); 
  38. if (isset ( $style ['font'] )) 
  39. $draw->setfont($style ['font'] ); 
  40. $draw->settextencoding('UTF-8'); 
  41. if (strtolower ($imagick->getImageFormat ()) == 'gif') { 
  42. foreach ( $imagick as $frame ) { 
  43. $frame->annotateImage ( $draw$x$y$angle$text ); 
  44. else { 
  45. $imagick->annotateImage ( $draw$x$y$angle$text ); 

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 万山特区| 台安县| 普安县| 许昌县| 利津县| 昌平区| 岳普湖县| 祁东县| 普陀区| 洮南市| 宜昌市| 陆河县| 岚皋县| 黄平县| 江源县| 吴堡县| 怀宁县| 莒南县| 唐河县| 巴林右旗| 灵璧县| 五华县| 平泉县| 东乌珠穆沁旗| 黎川县| 边坝县| 霍州市| 永春县| 舞阳县| 牡丹江市| 苏尼特左旗| 毕节市| 博爱县| 安图县| 南郑县| 沾化县| 高安市| 石林| 汾西县| 蚌埠市| 新昌县|