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.