画像に文字透かしと画像透かしを追加

9215 ワード

<?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();