I love the new zenphoto 1.1(.2) and am very excited about having all of the features I've gone though on my own and hacked together work out of the box. However, one thing I had going before I upgraded was image watermarking. This is a feature now officially supported, but it falls short at a critical spot. When you click to download the full size image, that has no watermark.
I solved this before by changing getFullImageURL() to getWateredFullImageURL() on the image page, this new function I wrote into template-functions.php. This takes you to a new page I made, a simple php script to on the fly return the image with a watermark.
This is a good way to consistently watermark your images, although it has it's downsides (broken after every upgrade). I think something to achieve the same means should to be included in the standard release.
This is full.php and it is put in my theme folder:
```
<?php <br />
header('content-type: image/jpeg');
$image_path = "/var/www/gallery/albums/" . $_GET[a] . "/" . $_GET[i];
$newim = imagecreatefromjpeg($image_path);
$watermark = imagecreatefrompng('/var/www/gallery/zp-core/images/watermatk2.png');
imagealphablending($watermark, false);
imagesavealpha($watermark, true);
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
// Position Overlay in Bottom Right
$dest_x = imagesx($newim) - $watermark_width - 20;
$dest_y = imagesy($newim) - $watermark_height - 20;
imagecopy($newim, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height);
imagedestroy($watermark);
imagejpeg($newim);
?>
`
This part goes after the function ```getFullImageURL()`
```
function getWateredFullImageURL() {
global $_zp_current_image;
$hi = "/gallery/page/full/?a=" . $_zp_current_image->getAlbumName() . "&i=" . $_zp_current_image->getFileName();
return $hi;
}
`
Comments
I will try this ASAP and get back with the results..
-add a mod_rewrite rule to .htaccess so it looks like it's a regular image. When you try to save a watermarked image from this it's filename is index.html?a=Album not IMG_2314.jpg.
-relocate this script to zp-core or incorporate it into i.php so it's not dependent on the theme.
I would love to spend a couple of days working the kinks out of it and learning mod_rewrite but I'm an overbooked high school senior.
I thought seniors just had to ditch classes to get more time . Anyway, if you do get some time to work this out, we'd be glad to add it to ZP!
We are getting ready to have a much better addons section and it would be great if it could be featured.
Also, to use this in your theme and not have to modify template-functions you could put the function at the top of your themes page or make a customfunctions.php page and include it in your theme page
I forgot to update my improved script I made a few weeks ago, all you have to do is add `header('Content-Disposition: attachment; filename="' . $_GET[i] . '"');` after the first header line, and this way the full image will have the correct filename when downloaded. If you don't want the image to download but show in the browser change attachment to inline.
Some suggestions.
if you change the url to something like `index.php?p=full.php&album=&image=` then you will travers through the normal zenphoto load to get to your full image page. This means that things like `$_zp_current_gallery->getAlbumFolder()` are available for your script. Also, you won't have to hard code in the URL information to get to the page in the `getWateredFullImageURL` function.
These things would go miles to making your functions more easily used by zp theme makers.
BTW, this change also supports password protected albums. If you haven't logged into the album, you won't be able to view the image.
Also, I was looking through google but never found a good answer: is there a way to preserve the exif data from the original photo when the watermark is added? That may be something to look into, although it's not too important..
You were a great help. It was your idea and basic design that was incorporated.
As for the EXIF data, I don't know. Maybe if we move to a different graphics library. You could put a new feature ticket into trac so we will remember if we do make the move.