phpʵÏÖ±³¾°Í¼ÉÏÌí¼ÓÔ²ÐÎlogoͼ±êµÄ·½·¨

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

±¾ÎÄʵÀý½²ÊoÁËphpʵÏÖ±³¾°Í¼ÉÏÌi¼ÓÔ²ÐÎlogoͼ±eµÄ½¨¡£*ÖÏi¸ø´o¼Ò¹(C)´o¼Ò²Î¿¼£¬¾ßÌaÈçÏ£º

˵һϲ½Öe£º

×ܹ²*Ö 3 ²½£º

1. ѹËologo ³É¹Ì¶¨´oСµÄ*½ÐÎͼƬ
2. ½«logo ת³ÉÔ²ÐÎlogo
3. ½«logoÓe±³¾°Í¼ºÏ²¢

*Ï»°²»¶a˵£¬Ö±½ÓÉÏ´uÂe£º


    <?php
    /**
     * ×÷Õߣºfriker
     * ¿ª*¢Ê±¼a£º20160516
     * ¹¦ÄÜ£ºÍ¼Æ¬´¦Ài
     *
     */
    class ImageController extends CI_Controller{
      public function __construct()
      {
        parent::__construct();
        date_default_timezone_set('Asia/Shanghai');
        error_reporting( E_ALL&~E_NOTICE&~E_WARNING);
        $this->load->library('curl');
      }
      /**
       * @todo : ±¾º¯ÊýÓÃÓÚ ½«*½ÐεÄͼƬѹËoºo
       *     Ôٲüo³ÉÔ²ÐÎ ×o³Élogo
       *     Óe±³¾°Í¼ºÏ²¢
       * @return *µ»Øurl
       */
      public function index(){
        //Í*Ïñ
        $headimgurl = 'a.jpg';
        //±³¾°Í¼
        $bgurl = './aa.png';
        $imgs['dst'] = $bgurl;
        //µÚÒ»²½ ѹËoͼƬ
        $imggzip = $this->resize_img($headimgurl);
        //µÚ¶þ²½ ²Ã¼o³ÉÔ²½ÇͼƬ
        $imgs['src'] = $this->test($imggzip);
        //µÚÈý²½ ºÏ²¢Í¼Æ¬
        $dest = $this->mergerImg($imgs);
      }
      public function resize_img($url,$path='./'){
        $imgname = $path.uniqid().'.jpg';
        $file = $url;
        list($width, $height) = getimagesize($file); //»ñȡԭͼ³ß´ç
        $percent = (110/$width);
        //Ëo*ųߴç
        $newwidth = $width * $percent;
        $newheight = $height * $percent;
        $src_im = imagecreatefromjpeg($file);
        $dst_im = imagecreatetruecolor($newwidth, $newheight);
        imagecopyresized($dst_im, $src_im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
        imagejpeg($dst_im, $imgname); //Êa³oѹËoºoµÄͼƬ
        imagedestroy($dst_im);
        imagedestroy($src_im);
        return $imgname;
      }
      //µÚÒ»²½Éu³ÉÔ²½ÇͼƬ
      public function test($url,$path='./'){
        $w = 110; $h=110; // original size
        $original_path= $url;
        $dest_path = $path.uniqid().'.png';
        $src = imagecreatefromstring(file_get_contents($original_path));
        $newpic = imagecreatetruecolor($w,$h);
        imagealphablending($newpic,false);
        $transparent = imagecolorallocatealpha($newpic, 0, 0, 0, 127);
        $r=$w/2;
        for($x=0;$x<$w;$x++)
          for($y=0;$y<$h;$y++){
            $c = imagecolorat($src,$x,$y);
            $_x = $x - $w/2;
            $_y = $y - $h/2;
            if((($_x*$_x) + ($_y*$_y)) < ($r*$r)){
              imagesetpixel($newpic,$x,$y,$c);
            }else{
              imagesetpixel($newpic,$x,$y,$transparent);
            }
          }
        imagesavealpha($newpic, true);
        // header('Content-Type: image/png');
        imagepng($newpic, $dest_path);
        imagedestroy($newpic);
        imagedestroy($src);
        unlink($url);
        return $dest_path;
      }
      //php ºÏ²¢Í¼Æ¬
      public function mergerImg($imgs,$path='./') {
        $imgname = $path.rand(1000,9999).uniqid().'.jpg';
        list($max_width, $max_height) = getimagesize($imgs['dst']);
        $dests = imagecreatetruecolor($max_width, $max_height);
        $dst_im = imagecreatefrompng($imgs['dst']);
        imagecopy($dests,$dst_im,0,0,0,0,$max_width,$max_height);
        imagedestroy($dst_im);
        $src_im = imagecreatefrompng($imgs['src']);
        $src_info = getimagesize($imgs['src']);
        imagecopy($dests,$src_im,270,202,0,0,$src_info[0],$src_info[1]);
        imagedestroy($src_im);
        // var_dump($imgs);exit;
        // header("Content-type: image/jpeg");
        imagejpeg($dests,$imgname);
        // unlink($imgs['dst']);
        unlink($imgs['src']);
        return $imgname;
      }
    }

½a¹uչʾ£º

¸u¶a¹ØÓÚPHPÏa¹ØÄÚÈݸÐÐËȤµÄ¶ÁÕ߿ɲe¿´±¾Õ¾×¨Ìa£º¡¶PHPͼÐÎÓeͼƬ²Ù×÷¼¼ÇÉ»a×Ü¡¡¢¡¶[PHP»u±¾Ói¨ÈeÃŽ̳Ì](http://www.jb51.net/Special/348.htm)¡¡¢¡¶[PHPÔËËaÓeÔËËauÓè×ܽa](http://www.jb51.net/Special/357.htm)¡¡¢¡¶phpÃaeÏo¶ÔÏo³ÌÐoÉe¼ÆÈeÃŽ̡̳¡¢¡¶PHPÍøÂç±a³Ì¼¼ÇÉ×ܽa¡¡¢¡¶PHPÊý×e(Array)²Ù×÷¼¼ÇÉ´oÈ«¡¡¢¡¶[php×Öu´®(string)Óè×ܽa](http://www.jb51.net/Special/47.htm)¡¡¢¡¶php+mysqlÊý¾Ý¿a²Ù×÷ÈeÃŽ̡̳¼°¡¶php³£¼uÊý¾Ý¿a²Ù×÷¼¼ÇÉ»a×Ü¡

Ï£Í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分页类完整实例