1<?PHP2 /**3 Add a watermark to a background image (location random)4 @param string $filename the background image to which you want to add a watermark5 @param string $water watermark picture6 */7 functionWatermark$filename,$water){8 //Gets the height and width of the background picture9 List($b _w,$b _h) =getimagesize($filename);Ten //Get the height and width of the watermark picture One List($w _w,$w _h) =getimagesize($water); A - $image _b= Imagecreatefromjpeg ($filename); - $image _w= Imagecreatefrompng ($water); the - //Set watermark picture location random - $posX=Rand(0, ($b _w-$w _w)); - $posY=Rand(0, ($b _h-$w _h)); + //Use the Imagecopy () function to copy a watermark picture to a specified position in a background picture -Imagecopy ($image _b,$image _w,$posX,$posY, 0, 0,$w _w,$w _h); + //header ("Content-type:image/jpeg"); A //Save a picture with a watermark image atImagejpeg ($image _b,$filename); - -Imagedestroy ($image _b); -Imagedestroy ($image _w); - } - inWatermark ("Mm2.jpg", "Btnbg.png"); -?>
Waterremark
Add image watermark to background image (location random)