<?php/** * created by phpstorm. * user: abo * date: 2016/ 1/6 0006 * time: pm 3:37 */class imagetool{ private $info; private $image; public function __ Construct ($SRC) { $info =getimagesize ($SRC); $this->info=array ( ' width ' = $info [0], ' height ' = $info [1], ' type ' = >image_type_to_extension ($info [2],false], ' MIME ' = $info [' MIME '] ); $fun = "imagecreatefrom{$this->info[' type '} "; $this->image= $fun ($SRC) ; } public function getimage () { return $this->image; } Public function getinfo () { return $this->info ; } /** * image Compression * @param $width * @param $height */ public function thumb ($width, $height) { $image _thumb=imagecreatetruecolor ($width, $height); imagecopyresampled ($image _thumb, $this->image,0,0,0,0, $width, $height, $this->info[ ' Width '], $this->info[' heIght ']) imagedestroy ($this->image); $this->image= $image _thumb; } /** * font watermark (default left corner) * @param $fontfile Font files consolaz.ttf * @param $text watermark content */ public function fontmark ($fontfile, $text) { //Red Green blue = white +50 transparency font $col = Imagecolorallocatealpha ($this->image, 255, 255, 255, 50); //Picture Font Composition-parameters: image, font size, deflection angle, transverse offset, portrait offset, color, font file, content imagettftext ($this->image, 50, 0, 40, $this->info[' height ']-50, $col, $fontfile, $text); } /** * Image Watermark * @param $water watermark image * @param $waterInfo Watermark Picture Information */ public function imagemark ($water, $ Waterinfo) { imagecopymerge ($this->image, $water, 20,30,0,0,$ waterinfo[' width ', $waterInfo [' Height '],20); /* image Synthesis-parameters: Target picture, Watermark picture, transverse offset, vertical offset, * watermark picture x at start copy, watermark image y start copy, * watermark Picture X at the end of the copy, Watermark image y at the end of the copy, Watermark image transparency. */ Imagedestroy ($water); } public function showinhtml () { header ("Content-type:".$this->info[' MIME ']); $funs = "image{$this->info[' type '}"; $funs ($this->image); } /** * Save pictures * @param $ newname Save file name */ public function saveimage ( $newName) { $funs = "image{$this->info[' type ']}"; $funs ($this->image, "$newName.". $this->info[' type ']);//Save Picture } public function __ Destruct () { imagedestroy ($this->image); }}
This article from the "from the More" blog, reproduced please contact the author!
GD picture processing class under TP_ frame (including basic PHP image processing ideas)