Link to home
Start Free TrialLog in
Avatar of acidburn2003
acidburn2003

asked on

Php + Gd watermark

Hi,

I need to generate a watermark on pictures using php and gd. I am a beginner to PHP so a little help would be appreciated.

For the first time i use this script:

<?php  

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);  

?>

But the problem is that the watermark is not nice. I want to apply some shadow, transaparency etc.

You can see an example of watermark on www.private.com at pic of the day. ATTENTION ! This site contains adult material.

At the bottom-right side of picture there is a watermark with their logo. It is very clear. How can i make a clear watermark like that ?

Thank you.
ASKER CERTIFIED SOLUTION
Avatar of Kiran Paul VJ
Kiran Paul VJ
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
download the source code from the top link in the page.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of basiclife
basiclife

My apologies, the proper example URL should've been http://www.ckdbristol.co.uk/tagimage.php?image=images%2Fgallery%2FChoi+Pics%2FOutside2.jpg

The previous one resized the image slightly...

For the record, kiranvj's link seems to be exactly what you're after as well, so I'd lean in favour of awarding to him - I'm not trying to steal points, just expand a little...
@acidburn,

glad to know the link helped.

@basiclife
ur code looks great, one thing i want to know is, will it accept any font file(ttf). Is it necessery to install the font in the server.

kiranvj
No "installation" required- all you need to do is copy the ttf file from your local machine to the webserver and point the code at it.  I've used everything from Arial through to Comic sans MS to Wingdings. the only thing to note is that sometimes the fonts I've found online do not seem compatible (about 5% of the time) - it will error saying "unable to load font" (or similar)

I've never found a reason. I'd imagine it's due to the font file being slightly malformed and windows dealing with it better than PHP, but I have never had the time to investigate

You can most likely find the fonts you want in c:\windows\Fonts (assuming windws ofc)

(And i just re-read my last post - excuse the typos, it's been a long day :)
Hi bacislife,  thanks for the info, i will try it out.

kiranvj