We help IT Professionals succeed at work.

Php + Gd watermark

acidburn2003
acidburn2003 asked
on
1,925 Views
Last Modified: 2013-12-13
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.
Comment
Watch Question

Computer Engineer
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Kiran Paul VJComputer Engineer
CERTIFIED EXPERT

Commented:
download the source code from the top link in the page.
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
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...
Kiran Paul VJComputer Engineer
CERTIFIED EXPERT

Commented:
@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 :)
Kiran Paul VJComputer Engineer
CERTIFIED EXPERT

Commented:
Hi bacislife,  thanks for the info, i will try it out.

kiranvj
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.