Watermark on Full Size Image

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

  • Thanks timo
    I will try this ASAP and get back with the results..
  • Awesome work timo!
  • A couple things need to be done for it to be viable:
    -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.
  • timo:

    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!
  • timo: would you mind adding this to the zenphoto hacks page? http://www.zenphoto.org/trac/wiki/ZenphotoHacks

    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
  • Someone emailed me asking for some further clarification of this hack. For this script to work one needs to fix the hard links to fit your setup. When the php code says `/var/www/gallery/albums/` or just `/gallery/` you need to change it to how it's set up on your computer. It may be "/var/www/t413.com/zenphoto/albums/" for example. There are three other instances of this hard linking you need to change, just look for /gallery/ and change that to how you named your zenphoto install folder.

    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.
  • timo:

    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.
  • This feature will be available in the 1.1.3 release due out soon. Themes will have to use the new function `getProtectedImageURL()` in place of `getFullImageURL()`. All the distributed themes have had this change made.

    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.
  • Sbillard: That's awesome, I'm glad it's being worked into the standard release. I'm sorry I couldn't help with it, perhaps after all my college apps are done in February I'll have time to help develop.

    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..
  • timo:

    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.
Sign In or Register to comment.