phpʹÓÃImagickÉú³ÉͼƬµÄ·½·¨

5年以前  |  阅读数:231 次  |  编程语言:PHP 

±¾ÎÄʵÀý½²ÊoÁËphpʹÓÃImagickÉu³ÉͼƬµÄ½¨¡£*ÖÏi¸ø´o¼Ò¹(C)´o¼Ò²Î¿¼¡£¾ßÌaÈçÏ£º

ÕaÀiʹÓÃImagick Éu³ÉͼƬ
½a¾oÁËͼƬдÖÐÎÄÎÄ×ÖÂÒÂeÎÊÌa£¬Ìi¼ÓÖ§³ÖµÄ×ÖÌa


    public function getPic(){
      header('Content-Type: text/html; charset=utf-8');
      $text = 'ÖÐÁ¸Íͺӣ¨sh600737£(C)';//ÖÐÁ¸Íͺӣ¨sh600737£(C)
      $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'; ///΢ÈiÑźÚ×ÖÌa ½a¾oÖÐÎÄÂÒÂe
      //$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 ();
    }
    // Ìi¼ÓˮӡÎÄ×Ö
    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 );
      }
    }

Ï£Íu±¾ÎÄËuÊo¶Ô´o¼ÒµÄphp³ÌÐoÉe¼ÆÓÐËu°iÖu¡£

 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
文件下载
贪吃蛇
获取IMEI
双位运算符
发送邮件
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
提取后缀名
年的日历图
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例