PHP Learning notes: Using the GD library to image a picture watermark

Source: Internet
Author: User
Tags imagecopy transparent color

<?Php$dst_path='1.jpg';//Target Picture$SRC _path ='Logo1.png';//Watermark Picture//create an instance of a picture$DST =imagecreatefromstring (file_get_contents ($DST _path)); $src=imagecreatefromstring (file_get_contents ($src _path));//Get the width height of the watermark pictureList ($src _w, $src _h) =getimagesize ($src _path);//the watermark picture is copied to the target image, the last parameter 50 is set transparency, here to achieve the translucent effect, two 20 is the control of the watermark coordinates positionImagecopymerge ($DST, $SRC, -, -,0,0, $src _w, $src _h, -);//if the watermark picture itself has a transparent color, use the Imagecopy method//imagecopy ($DST, $SRC, ten, 0, 0, $src _w, $src _h);//Output PictureList ($dst _w, $dst _h, $dst _type) =getimagesize ($dst _path);Switch($dst _type) { Case 1://GIFHeader'Content-type:image/gif');        Imagegif ($DST);  Break;  Case 2://JPGHeader'Content-type:image/jpeg');        Imagejpeg ($DST);  Break;  Case 3://PNGHeader'Content-type:image/png');        Imagepng ($DST);  Break; default:         Break;} Imagedestroy ($DST); Imagedestroy ($SRC);?>

Effect:

PHP Learning notes: Using the GD library to image a picture watermark

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.