Here would be a pretty good start.. but I dont think it is in the plans for ZenPhoto for a little while.
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.
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
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.
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.
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).
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).
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.
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
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.
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.