Create a text watermark<?php//Text watermark */* Open picture *///1. Configure picture path $SRC = "4.jpg";//2. Get information about a picture (get basic information about a picture) $info = getimagesize ($SRC);//3. By getting the picture type $type = Image_type_to_extension ($info [2],false);//4. Create a picture of the same image type in memory $fun = "imagecreatefrom{$type}";//5. Picture copied into memory $image = $fun ($SRC);/* manipulate picture *///1. Set the path of the font $font = "Stliti. TTF ";//c disk WINDOWS/FONTS//2. Fill in the watermark $content = ' Hello '//3. Set the color of the font RGB and transparency $col = Imagecolorallocatealpha ($image, 255,255,255,50)//4. Write Text Imagettftext ($image, 20,0,20,30, $col, $font, $content);/* Output picture *///browser Output header (" content-type:{$info [' MIME ']} "$func =" image{$type} "; $func ($image);//Save Picture $func ($image, ' newimage. '). $type)/* Destroy picture */imagedestroy ($image);? >Create a picture watermark<?php $dst _path = ' 4.jpg '; $src _path = ' 1.png ';//Create an instance of the picture $dst = Imagecreatefromstring (file_get_contents ($DST _path)); $SRC = imagecreatefromstring (file_get_contents ($src _path)),//Get the width of the watermark image list ($src _w, $src _h) = getimagesize ($src _path )///To copy the watermark picture to the target image, the last parameter 80 is to set the transparency, here to achieve the translucent effect Imagecopymerge ($DST, $SRC, ten, ten, 0, 0, $src _w, $src _h, 80);//If the watermark picture itself with transparent color, Then use the Imagecopy method//imagecopy ($DST, $SRC, ten, 0, 0, $src _w, $src _h);//Output Picture list ($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);? >
PHP generated text watermark and image watermark