Image add text watermark and picture watermark

Source: Internet
Author: User
 Php/** * @desc image Processing Class*/     classpic{Private $info; Private $res;  Public $thumb _pic;  Public function__construct ($picPath){            //Get picture information            $this->info =getimagesize($picPath); //Get Picture name            $this->info[' type '] = image_type_to_extension ($this->INFO[2],false); $funs= ' Imagecreatefrom '.$this->info[' type ']; $this->res =$funs($picPath); }        //thumbnail Images         Public functionThumb$w=100,$h=100){            //Create a picture resource            $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; }        //Show         Public functionShowpic () {Header(' Content-type: '.$this->info[' type ']); $funs= ' image '.$this->info[' type ']; $funs($this-res); }                //Save         Public functionSavepic ($newname){            $funs= ' image '.$this->info[' type ']; $funs($this->res,$newname.".".$this->info[' type ']); }                //Destroying pictures         Public function__destruct () {Imagedestroy ($this-res); }        /** * @desc Add text watermark * @param $content string literal * @param $fonturl string Font path *         @param $fontsize int Font size * @param $fontcolor array Set color and transparency * @param $local array watermark coordinates * @param $fontangle int font rotation angle*/         Public functionFontmark ($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 Add picture watermark * @param $markPic string watermark picture * @param $local array picture coordinates * @para M $alpha array to set color and transparency*/         Public functionPicmark ($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=NewPic (' yibo_pic28.jpg '); $pic->picmark (' Logo3.png ',Array(' x ' =>50, ' y ' =>50), 30); $pic->showpic ();

The above describes the picture to add text watermark and image watermark, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.