Prevent download without watermarks: how-to

alecmyers

Joined: 2006-08-01
Posts: 3366
Posted: Thu, 2009-04-23 11:19

Probably most people know that if you set a watermark on a picture Gallery creates a "preferred" derivative with the watermark composited on top. The browser is directed to download the preferred derivative instead of the original so the watermark shows up. Keeping the original means you can remove/replace the watermark in future.

However preferred derivatives and original items share the same Gallery permissions. So if you give someone (guest user for instance) permission to see the original expecting that they will *only* be able to see the watermarked version, you're out of luck. With a bit of guesswork and url-fiddling it's possible for anyone to download the unwatermarked version too.

There are two solutions: The first is to create a resize the same size as the original, watermark the resize, and allow guest users permission only to see resizes.

The second is a small hack which prevents an original item being downloaded *ever* if a preferred derivative exists. This might be more suitable for your gallery installation. It will cause problems if you use printing services or other things that need behind-the-scenes access to the original items though. (Gallery itself can still access the original, it just won't ever serve it over the web any more.)

Here's the hack:

Edit modules/core/DownloadItem.inc, adding these lines at line 73:

  list ($ret, $item) = GalleryCoreApi::fetchPreferredSource($item);
  if ($ret) {
     return $ret;
  }
  $itemId = $item->getId();

I hope that's useful to someone.

If you test it out, remember that Gallery's fast-download system (which bypasses most of the gallery code to quickly send an image which is public and has been cached) will still send the original without the watermark if it's in the relevant cache even after you've added this code.

Login or register to post comments