PHP image operations

Source: Internet
Author: User
The PHP image Operation class is based on the various Image operation methods that have been provided. here I have summarized a PHP image Operation class, including adding text watermarks, image watermarks, and compressed images to images. You can add functions by yourself.

 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);} // image watermark public function imageMark ($ src, $ locate, $ alpha) {$ info2 = getimagesize ($ src ); $ type2 = image_type_to_extension ($ info2 [2], false); $ fun2 = "imagecreatefrom ". $ type2; $ water = $ fun2 ($ src); imagecopymerge ($ this-> image, $ water, $ locate ['x'], $ locate ['Y'], 0, 0, $ info2 [0], $ info2 [1], $ alpha); imagedestroy ($ water);} // Display public function show () in the browser () {header ("Content-type :". $ this-> info ['Mime ']); $ fun = "image ". $ this-> type; $ fun ($ this-> image);} // save as the public function save ($ newname) file {$ fun = "image ". $ this-> type; $ fun ($ this-> image, $ newname. '. '. $ this-> type);} public function _ destruct () {imagedestroy ($ this-> image );}}



Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.