Add text and image watermarks to images, add text watermarks to images _ PHP Tutorial

Source: Internet
Author: User
Add text and image watermarks to images, and add text watermarks to images. Add text and image watermarks to images, and add text watermarks to images? Php *** @ desc image processing class * classPic {private $ info; private $ res; public $ thumb_pic; publicfunct image adding text watermark and image watermark, adding text watermark image
 Info = getimagesize ($ picPath); // Obtain the image name $ this-> info ['type'] = image_type_to_extension ($ this-> info [2], false ); $ funs = 'imagecreatefrom '. $ this-> info ['type']; $ this-> res = $ funs ($ picPath);} // Thumbnail public function thumb ($ w = 100, $ h = 100) {// create an image resource $ image_thumb = imagecreatetruecolor ($ w, $ h); imagecopyresampled ($ image_thumb, $ this-> res, $ w, $ h, $ this-> info [0], $ this-> info [1]); imagedestroy ($ this-> res ); $ this-> res = $ image_thumb;} // Display public function showPic () {header ('content-type :'. $ this-> info ['type']); $ funs = 'image '. $ this-> info ['type']; $ funs ($ this-> res);} // save the public function savePic ($ newname) {$ funs = 'image '. $ this-> info ['type']; $ funs ($ this-> res, $ newname. ". ". $ this-> info ['type']);} // destroy the image public function _ destruct () {imagedestroy ($ this-> res );} /*** @ desc add a text watermark * @ param $ content string text * @ param $ fonturl string font path * @ param $ fontsize int font size * @ param $ fontcolor array set color and transparency * @ param $ local array watermark coordinate * @ param $ fontangle int font rotation angle */public function fontMark ($ 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 an image watermark * @ param $ markPic string watermark image * @ param $ local array image coordinate * @ param $ alpha array set color and transparency */public function picMark ($ 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 = new Pic('yibo_pic28.jpg '); $ pic-> picMark('logo3.png ', array ('x' => 50, 'y' => 50), 30); $ pic-> showPic ();

Watermark and image watermark, add text watermark image? Php/*** @ desc image processing class */class Pic {private $ info; private $ res; public $ thumb_pic; public funct...

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.