<?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