-
-
//Add image watermark (random position) to the background image, the background image format is jpeg, and the watermark image format is gif - function watermark($filename,$water){
//Get the width and height of the background image
- list($b_w,$b_h) = getimagesize($filename);
//Get the watermark image The width and height of
- list($w_w,$w_h) = getimagesize($water);
//Random starting position of the watermark image in the background image
- $posX = rand (0, ($b_w-$w_w));
- $posY = rand(0, ($b_h-$w_h));
//Resources for creating background images
- $back = imagecreatefromjpeg($filename);
//Resources for creating watermark images
- $water = imagecreatefromgif($water);
//Use the imagecopy() function Copy the watermark image to the location specified by the background image
- imagecopy($back, $water, $posX, $posY, 0, 0, $w_w, $w_h);
//Save Background image with watermark image
- imagejpeg($back,$filename);
- imagedestroy($back);
- imagedestroy($water);
- }
//Output watermark image
- watermark ("brophp.jpg", "logo.gif");
- ?>
-
Copy code
|