Php watermarking code (supports translucent and transparent watermarks and png transparent backgrounds)

Source: Internet
Author: User

Copy codeThe Code is as follows: // the original image
$ Dst = "/upload/20120914/20120914040740 -0.jpg"; // ensure that the image path is correct.
// Obtain the original image information
$ Dst_info = getimagesize ($ dst );
Switch ($ dst_info [2])
{
Case 1:
$ Dst_im = imagecreatefromgif ($ dst); break;
Case 2:
$ Dst_im = imagecreatefromjpeg ($ dst); break;
Case 3:
$ Dst_im = imagecreatefrompng ($ dst); break;
Case 6:
$ Dst_im = imagecreatefromwbmp ($ dst); break;
Default:
Die ("unsupported file type 1"); exit;
}
// Watermark image
$ Src = "/images/shuiyin.png"; // note that the path must be written
$ Src_info = getimagesize ($ src );
Switch ($ src_info [2])
{
Case 1:
$ Src_im = imagecreatefromgif ($ src); break;
Case 2:
$ Src_im = imagecreatefromjpeg ($ src); break;
Case 3:
$ Src_im = imagecreatefrompng ($ src); break;
Case 6:
$ Src_im = imagecreatefromwbmp ($ src); break;
Default:
Die ("unsupported file type 1"); exit;
}

// Translucent watermark
// $ Alpha = 50; // watermark transparency
// Imagecopymerge ($ dst_im, $ src_im, $ dst_info [0]-$ src_info [0]-10, $ dst_info [1]-$ src_info [1]-10, 0, 0, $ src_info [0], $ src_info [1], $ alpha );

// Supports png transparency.
Imagecopy ($ dst_im, $ src_im, $ dst_info [0]-$ src_info [0]-10, $ dst_info [1]-$ src_info [1]-10, 0, 0, $ src_info [0], $ src_info [1]);

// Save the image
Switch ($ dst_info [2]) {
Case 1:
Imagegif ($ dst_im, $ dst); break;
Case 2:
Imagejpeg ($ dst_im, $ dst); break;
Case 3:
Imagepng ($ dst_im, $ dst); break;
Case 6:
Imagewbmp ($ dst_im, $ dst); break;
Default:
Die ("unsupported file type 2"); exit;
}
Imagedestroy ($ dst_im );
Imagedestroy ($ src_im );

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.