ZenphotoCMS Forum
Image Watermarking/ Copyright with GD - Printable Version

+- ZenphotoCMS Forum (https://forum.zenphoto.org)
+-- Forum: Support (https://forum.zenphoto.org/forum-1.html)
+--- Forum: General support (https://forum.zenphoto.org/forum-4.html)
+--- Thread: Image Watermarking/ Copyright with GD (/thread-505.html)

Pages: 1 2 3 4


Image Watermarking/ Copyright with GD - nathan - 14-05-2006

I was wondering if anyone has made is possible to add a pre-defined copyright notice to all the images generated by Zenphoto using GD? I would love to have this feature. If anyone could lend a hand, I would much appreciate it.

Thanks,
Nathan




Image Watermarking/ Copyright with GD - Chilifrei64 - 14-05-2006

Here would be a pretty good start.. but I dont think it is in the plans for ZenPhoto for a little while.

http://www.sitepoint.com/article/watermark-images-php




Image Watermarking/ Copyright with GD - nathan - 17-05-2006

Trisweb, (or anyone else who knows it inside out), can you tell me where I should look at putting the watermarking function, as the images are generated on the fly, it is not as though we are dealing with fixed files here.

I am a little confused, so if anyone could clear it up, I would appreciate it.




Image Watermarking/ Copyright with GD - trisweb - 17-05-2006

All image processing is done in [b]i.php[/b], so that's where you'd want to add the watermarks. It'd actually be very easy to do, pretty much how that link describes it.




Image Watermarking/ Copyright with GD - nathan - 18-05-2006

Okay. I knew that I needed to play around with i.php (and zen_config.php, but I'll get to that), but, where exactly, and how many times to I need to call the function? I notice that there are 3 different ways in which i.php returns an image:

[list=1]
[]If there are no parameters specified,
[
]If the requested image is the same size or smaller than the original,
[*] and if the image was cropped.
[/list]
Does that mean I have to run the function on all of those outputs?

Also, is it as simple as adding: $conf['perform_watermark'] = true; in the zen_config.php file, setting the new variable at the top of i.php (just for convenience) and the adding a simple conditional statement to determine if the watermark will actually take place? I might one day want to turn this off, and I would rather not have to edit the code. It is a much nicer way of doing it I think. I understand that I would need to clear the cache if I changed the setting, for it to take effect on existing images, but that is fine.

Any more help would be much appreciated. I am really tring to understand the workings of i.php, there is still a bit to learn and this isn't THAT easy for me.

Thanks,
Nathan




Image Watermarking/ Copyright with GD - trisweb - 18-05-2006

Yep, that sounds great.

You only need to do it once to the final image reference, right before the imagejpeg call.

If you actually want to be using this for a while, I highly recommend getting the latest code from SVN (You can get there through the development section of the wiki). It's got quite a few new features for the next version like custom crops. You'll still do the same thing though, just right before imagejpeg, add your watermark.

i.php is probably the most confusing part of zenphoto... not too bad though It's better in the latest code, I cleaned it up quite a bit and added lots of good comments.




Image Watermarking/ Copyright with GD - nathan - 18-05-2006

I've got the latest SVN, WITH the crops (I asked for it, remember ).

Thanks. I'll give it a go now and see how it turns out. Thanks for your help (again).




Image Watermarking/ Copyright with GD - nathan - 19-05-2006

Didn't work for me. I can't be sure i did it correctly, but i.php stopped generating images altogether which to me, is a sure sign I broke something.

How about this. A little more help (i.e., show me what [exactly] to put where [exactly]) and I donate a little more to zenphoto fund for your time.

I had all the cropping stuff set up for the desktops/ wallpaper site I am working on, but it cut out the copyright notices on the images (we could never be sure where to put them), so we need to use PHP and put in the bottom corner when we are done hacking them to pieces.

Any more help would be great.




Image Watermarking/ Copyright with GD - nathan - 19-05-2006

Here is where I am getting stuck: (i think)
What do I actually use for the image value in this - $image = imagecreatefromjpeg($_GET['src']);? Is it - $newfile?

This is the bottom end of my i.php file, to give you an idea where I am at, or getting it wrong:
` // Create the cached file (with lots of compatibility)...

    touch($newfile);

    //-- watermarking

    $watermark = imagecreatefrompng('watermark.png');  

    $watermark_width = imagesx($watermark);  

    $watermark_height = imagesy($watermark);  

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

    $wimage = imagecreatefromjpeg($newfile]);  

    $size = getimagesize($newfile);  

    $dest_x = $size[0] - $watermark_width - 5;  

    $dest_y = $size[1] - $watermark_height - 5;  

    imagecopymerge($wimage, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);      

    imagedestroy($watermark);

    $newfile = $wimage;

    //-- /watermarking

    imagejpeg($newim, $newfile, $quality);

chmod($newfile,0644);

    imagedestroy($newim);

    imagedestroy($im);

}

}

// ... and redirect the browser to it.

header("Location: " . PROTOCOL . "://" . $_SERVER['HTTP_HOST'] . WEBPATH . "/cache$newfilename");

?>`

Sorry for the double/triple posting. I am trying to do it myself, and learn the workings of i.php.

Thanks for your patience (with me).




Image Watermarking/ Copyright with GD - trisweb - 20-05-2006

Quite a few syntax errors in there... whew.

Alright, lemme think...

//-- watermarking
$watermark = imagecreatefrompng('watermark.png');
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$dest_x = $neww - $watermark_width - 5;
$dest_y = $newh - $watermark_height - 5;
imagecopymerge($newim, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);

imagedestroy($watermark);

//-- /watermarking

Yeah, I think that should work. Hasn't been tested though, so come back if you have problems. It's a lot simpler than you were trying to do though.... just make an image from the watermark, get some positions, and merge it onto the existing image ($newim).




Image Watermarking/ Copyright with GD - nathan - 21-05-2006

wow.

It works (perfectly). Thank you so much for your help and time.

As I said I would, when I get home this evening, I will put another donation into the zenphoto fund.

I really appreciate this. It works really well, and it didn't slow down image generation by that much, which is a plus.




Image Watermarking/ Copyright with GD - nathan - 21-05-2006

The code you posted works, but, through no error in your code, the overlayed image look terrible.

I think it is because I am using images with white text over a tranparent background. While I am using PNG-8 formatted files (as the article suggests), I still think it is the transparency that is the issue.

Can you suggest a way around this? I found the following at php.net, that looks like it will do the job, but I have no idea how to use it, how it will work with what we have at present, so I will put it here (first reply/comment on this page): http://au3.php.net/manual/en/function.imagecopymerge.php




Image Watermarking/ Copyright with GD - nathan - 21-05-2006

I could just print text to the image, but I don't know how to do that either! As it is a opyright notice, it could be easier.




Image Watermarking/ Copyright with GD - trisweb - 22-05-2006

Use an alpha-transparent PNG with anti-aliased edges. In fact, usually watermarks are partly transparent anyway... Fireworks or Photoshop can do that, and the GD library should be able to merge them just fine.




Image Watermarking/ Copyright with GD - nathan - 23-05-2006

I used an alpha-transparent PNG with anti-aliased edges, with file format PNG-8, and it still looks rubbish. I think it is because the font is small/ thin. Or GD is not as nice as I would have thought.

You can see the output of one watermark run here:
http://server.skoap.com/zen.jpg

I think having GD write directly to the file is looking nice.




Image Watermarking/ Copyright with GD - trisweb - 23-05-2006

Well, imagecopymerge is probably the wrong function to use for true alpha-PNG overlay... I'm sure you could look it up and see.

If the text works though, cool.




Image Watermarking/ Copyright with GD - nathan - 27-05-2006

Just to let anyone else know (if someone is interested in the same process later), that to get this working working with png-24 formated image that supports antialiasing and alpha transparency, you need add/change the following.

`imagealphablending($watermark, false);

imagesavealpha($watermark, true);`

Also, you need to use imagecopy instead of imagecopymerge.

Thanks everyone for there help.




Image Watermarking/ Copyright with GD - DarrellD - 27-05-2006

Nathan, how about summarizing this info and putting it in the wiki under the Hacks section? Others may find it helpful.




Image Watermarking/ Copyright with GD - nathan - 30-05-2006

Sounds like an idea. I will get to it this afternoon.




Image Watermarking/ Copyright with GD - DarrellD - 04-06-2006

Nathan, did you ever get to it?