Jump to content

[SOLVED] transparent watermarks on images


gerkintrigg

Recommended Posts

hello

I'm using the code below to make a watermark and it's kinda working, but I want it semi-transparent as the PNG file is itself. Is there an easy way of overlaying transparent images in the GD library, so that the original image is merged in such as way that it can be seen through the watermark?

 

Thanks... code to follow.

 

header('content-type: image/jpeg');  

$watermark = imagecreatefrompng('watermark.png');  
$watermark_width = imagesx($watermark);  
$watermark_height = imagesy($watermark);  
$image = imagecreatetruecolor($watermark_width, $watermark_height);  
$image = imagecreatefromjpeg($_GET['src']);  
$size = getimagesize($_GET['src']);  
$dest_x = $size[0] - $watermark_width - 5;  
$dest_y = $size[1] - $watermark_height - 5;  
imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);  
imagejpeg($image);  
imagedestroy($image);  
imagedestroy($watermark);  

Link to comment
https://forums.phpfreaks.com/topic/57379-solved-transparent-watermarks-on-images/
Share on other sites

try adjusting the last argument in the imagecopymerge() to get the desired effect.

 

BTW, the first is redundant:

 

$image = imagecreatetruecolor($watermark_width, $watermark_height); 

$image = imagecreatefromjpeg($_GET['src']);

That's not exactly what I was looking for, but thanks. That did solve another problem. ;o)

 

My main issue now is:

The watermark PNG has transparent areas in it. Is there any way of preserving these areas like I can in photoshop when layering images with transparent backgrounds.

 

I hope that makes sense.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.