PHP & Watermarking Images

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

PHP & Watermarking Images

Post by Mr Tech »

I need a tutorial on how to watermark an image... here are the details:

The client uploads the pictures to the web server without the watermark. Then we have a PHP file that links to the image file (E.g: <img src="watermark.php?image=image.jpg">) which then adds the watermark to the image. The watermark can be either text or an image... Most likely text that would span across the image... This will prevent people from saving the picture on their computer without purchasing it.

I found this article (http://www.sitepoint.com/article/watermark-images-php) but it places the image at the bottom right which is not what I want... I'd tather it in the center...

Any ideas, scripts or tutorials you know of?
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

In that tuturial change the dst_x,dst_y or src_x,src_y to change where the image goes

Code: Select all

int imagecopymerge ( resource dst_im, resource src_im, int dst_x, int dst_y, int src_x, int src_y, int src_w, int src_h, int pct )
EDIT:
//I posted too quickly....

Code: Select all

//just change this:
$size = getimagesize($_GET['src']);  
$dest_x = $size[0] - $watermark_width - 5;  
$dest_y = $size[1] - $watermark_height - 5;
Last edited by hawleyjr on Sun Jul 10, 2005 11:55 pm, edited 1 time in total.
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

Post by Mr Tech »

Thanks hawleyjr...

But what if the image is a different size? If you had a really big image and really small image using the same:

Code: Select all

$size = getimagesize($_GET['src']);  
$dest_x = $size[0] - $watermark_width - 5;  
$dest_y = $size[1] - $watermark_height - 5;
Wouldn't it put it in a different spot? I need it cenetr all the time...
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Code: Select all

$size = getimagesize($_GET['src']);  
$dest_x = ($size[0]/2) - ($watermark_width/2);  
$dest_y = ($size[1]/2) - ($watermark_height/2);
Should work for any image size.t/2);

Should work for any image size.;0]/2) - ($watermark_width/2);
$dest_y = ($size[1]/2) - ($watermark_height/2);

Should work for any image size.$size = getimagesize($_GET['src']);
$dest_x = ($size[0]/2) - ($watermark_width/2);
$dest_y = ($size[1]/2) - ($watermark_height/2);

Should work for any image size.;1]/2) - ($watermark_height/2);

Should work for any image size.e[1]/2) - ($watermark_height/2);

Should work for any image size.11;1]/2) - ($watermark_height/2);

Should work for any image size.2);
$dest_y = ($size[1]/2) - ($watermark_height/2);

Should work for any image size.
$dest_x = ($size[0]/2) - ($watermark_width/2);
$dest_y = ($sizeї1]/2) - ($watermark_height/2);

Should work for any image size.p]
Should work for any image size.);
$dest_x = ($size[0]/2) - ($watermark_width/2);
$dest_y = ($sizeї1]/2) - ($watermark_height/2);

Should work for any image size.ht/2);

Should work for any image size.ze($_GET['src']);
$dest_x = ($size[0]/2) - ($watermark_width/2);
$dest_y = ($sizeї1]/2) - ($watermark_height/2);

Should work for any image size.
$dest_x = ($sizeї0]/2) - ($watermark_width/2);
$dest_y = ($size[1]/2) - ($watermark_height/2);

Should work for any image size.);
$dest_x = ($sizeї0]/2) - ($watermark_width/2);
$dest_y = ($sizeї1]/2) - ($watermark_height/2);

Should work for any image size.size($_GET['src']);
$dest_x = ($size[0]/2) - ($watermark_width/2);
$dest_y = ($sizeї1]/2) - ($watermark_height/2);

Should work for any image size. ($watermark_height/2);

Should work for any image size.= getimagesize($_GET['src']);
$dest_x = ($size[0]/2) - ($watermark_width/2);
$dest_y = ($size[1]/2) - ($watermardest_x = ($size[0]/2) - ($watermark_width/2);
$dest_y = ($size[1]/2) - ($watermark_height/2);

Should work for any image size. - ($watermark_width/2);
$dest_y = ($size[1]/2) - ($watermark_height/2);

Should work for any image sizeage size.$size = getimagesize($_GET['src']);
$dest_x = ($size[0]/2) - ($watermark_width/2);
$dest_y = ($sizeї1]/2) - ($watermark_height/2);

Should work for any image size.11;0]/2) - ($watermark_width/2);
$dest_y = ($size[1]/2) - ($watermark_height/2);

Should work for any image size.$size = getimagesize($_GET['src']);
$dest_x = ($size[0]/2) - ($watermark_width/2);
$dest_y = ($size[1]/2) - ($watermark_height/2);
[/php:rmark_width/2);
$dest_y = ($size[1]/2) - ($watermark_height/2);

Should work for any image size.size.
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

Post by Mr Tech »

Awesome! Thanks a lot! I was going to ahev to pay $400 for this :roll:

Cheers
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Mr Tech wrote:Awesome! Thanks a lot! I was going to ahev to pay $400 for this :roll:

Cheers
lol,lol, pay me,pay me!!!
Post Reply