圖片添加文字浮水印 和圖片浮水印,添加文字浮水印圖片_PHP教程

來源:互聯網
上載者:User

圖片添加文字浮水印 和圖片浮水印,添加文字浮水印圖片


php    /**     * @desc 圖片處理類     */     class Pic{        private $info;        private $res;        public $thumb_pic;        public function __construct($picPath){            //擷取圖片資訊            $this->info = getimagesize($picPath);            //擷取圖片名            $this->info['type'] = image_type_to_extension($this->info[2],false);            $funs = 'imagecreatefrom'.$this->info['type'];            $this->res = $funs($picPath);        }        //縮圖        public function thumb($w=100,$h=100){            //建立圖片資源            $image_thumb = imagecreatetruecolor($w,$h);            imagecopyresampled($image_thumb,$this->res,0,0,0,0,$w,$h,$this->info[0],$this->info[1]);            imagedestroy($this->res);            $this->res = $image_thumb;        }        //展示        public function showPic(){            header('Content-type:'.$this->info['type']);            $funs = 'image'.$this->info['type'];            $funs($this->res);                }                //儲存        public function savePic($newname){            $funs = 'image'.$this->info['type'];            $funs($this->res,$newname.".".$this->info['type']);                        }                //銷毀圖片        public function __destruct(){            imagedestroy($this->res);                }        /**         * @desc  添加文字浮水印         * @param $content string    文字         * @param $fonturl string     字型路徑         * @param $fontsize int       字型大小         * @param $fontcolor array     設定顏色和透明度         * @param $local array      浮水印座標         * @param $fontangle int    字型旋轉角度         */        public function fontMark($content,$fonturl,$fontsize,$fontcolor,$local,$fontangle){            $color = imagecolorallocatealpha($this->res,$fontcolor[0],$fontcolor[1],$fontcolor[2],$fontcolor[3]);            imagettftext($this->res,$fontsize,$fontangel,$local['x'],$local['y'],$color,$fonturl,$content);                }        /**         * @desc  添加圖片浮水印         * @param $markPic string 浮水印圖片         * @param $local array     圖片座標         * @param $alpha array     設定顏色和透明度         */        public function picMark($markPic,$local,$alpha){            $markInfo = getimagesize($markPic);            $markType = image_type_to_extension($markInfo[2],false);            $markFun = 'imagecreatefrom'.$markType;            $markWater = $markFun($markPic);            imagecopymerge($this->res,$markWater,$local['x'],$local['y'],0,0,$markInfo[0],$markInfo[1],$alpha);            imagedestroy($markWater);                }     }     $pic = new Pic('yibo_pic28.jpg');     $pic->picMark('logo3.png',array('x'=>50,'y'=>50),30);     $pic->showPic();

http://www.bkjia.com/PHPjc/965017.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/965017.htmlTechArticle圖片添加文字浮水印 和圖片浮水印,添加文字浮水印圖片 ? php /* * * @desc 圖片處理類 */ class Pic{ private $info ; private $res ; public $thumb_pic ; public funct...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.