Based on the various image manipulation methods that have been given, I have summed up a class of PHP image operation, including adding text watermark, image watermark and compressed image to the image.
Readers can add their own functions.
<?Phpclass Image {Private $info;p rivate $type;p rivate $iamge;/*** open picture, write memory ***/public function __construct ($src) {$this-& Gt;info = getimagesize ($src), $this->type = image_type_to_extension ($this->info[2],false); $fun = " Imagecreatefrom ". $this->type; $this->image = $fun ($SRC);} Thumbnail public function thumb ($width, $height) {$image _thumb = Imagecreatetruecolor ($width, $height); Imagecopyresampled ( $image _thumb, $this->image, 0, 0, 0, 0, $width, $height, $this->info[0], $this->info[1]); Imagedestroy ($this- >image); $this->image = $image _thumb;} Text watermark Public Function Fontmark ($content, $fontUrl, $size, $color, $locate =array (' x ' =>0, ' y ' =>0), $angle =0) {$ color = Imagecolorallocatealpha ($this->image, $color [0], $color [1], $color [2], $color [3]); Imagettftext ($this Image, $size, $angle, $locate [' X '], $locate [' Y '], $color, $FONTURL, $content);} Picture watermark Public Function ImageMark ($SRC, $locate, $alpha) {$info 2 = getimagesize ($SRC); $type 2 = image_type_to_extension ($ INFO2[2],FALSE); $fun2 = "Imagecreatefrom". $type 2; $water = $fun 2 ($SRC); Imagecopymerge ($this->image, $water, $locate [' X '], $locate [' Y '], 0, 0, $info 2[0], $info 2[1], $alpha); Imagedestroy ($water);} The Public Function show () {header ("Content-type:" $this->info[' MIME ') is displayed in the browser, $fun = "image". $this->type; $fun ( $this->image);} Save as file Public function Save ($newname) {$fun = "image". $this->type; $fun ($this->image, $newname. $this->type);} Public Function __destruct () {Imagedestroy ($this->image);}}
PHP Image Manipulation Class