Added an image watermark using the phpimagecopy function.
// Add an 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 ){
// Obtain the width and height of the background image.
- List ($ B _w, $ B _h) = getimagesize ($ filename );
// Obtain the width and height of the watermark image
- List ($ w_w, $ w_h) = getimagesize ($ water );
// Place the watermark position in the background image at random start position
- $ PosX = rand (0, ($ B _w-$ w_w ));
- $ PosY = rand (0, ($ B _h-$ w_h ));
// Create background image resources
- $ Back = imagecreatefromjpeg ($ filename );
// Create watermark image resources
- $ Water = imagecreatefromgif ($ water );
// Use the imagecopy () function to copy the watermark image to the position specified in the background image.
- Imagecopy ($ back, $ water, $ posX, $ posY, 0, 0, $ w_w, $ w_h );
// Save the background image with the watermark
- Imagejpeg ($ back, $ filename );
- Imagedestroy ($ back );
- Imagedestroy ($ water );
- }
// Output watermark image
- Watermark ("brophp.jpg", "logo.gif ");
- ?>
|