PHP Watermark code (supports translucent transparent water print, PNG transparent background support) _php instance

Source: Internet
Author: User

Copy Code code as follows:

Original image
$DST = "/upload/20120914/20120914040740-0.jpg"; Note that the picture path should be correct
Get the original picture information
$DST _info = getimagesize ($DST);
Switch ($DST _info[2])
{
Case 1:
$DST _im =imagecreatefromgif ($DST);
Case 2:
$DST _im =imagecreatefromjpeg ($DST);
Case 3:
$DST _im =imagecreatefrompng ($DST);
Case 6:
$DST _im =imagecreatefromwbmp ($DST);
Default
Die ("Unsupported file type 1"); exit;
}
Watermark Image
$SRC = "/images/shuiyin.png"; Note that the path should be written to
$src _info = getimagesize ($SRC);
Switch ($src _info[2])
{
Case 1:
$SRC _im =imagecreatefromgif ($SRC);
Case 2:
$SRC _im =imagecreatefromjpeg ($SRC);
Case 3:
$SRC _im =imagecreatefrompng ($SRC);
Case 6:
$SRC _im =imagecreatefromwbmp ($SRC);
Default
Die ("Unsupported file type 1"); exit;
}

semitransparent format 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);

Ways to support transparency in PNG itself
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 picture
Switch ($DST _info[2]) {
Case 1:
Imagegif ($dst _im, $DST);
Case 2:
Imagejpeg ($dst _im, $DST);
Case 3:
Imagepng ($dst _im, $DST);
Case 6:
Imagewbmp ($dst _im, $DST);
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.