Watermarking module.

jelwell

Joined: 2003-05-29
Posts: 115
Posted: Thu, 2004-10-14 22:11

I'm thinking about adding a few features to watermarking.

1) Ability to watermark text instead of an image.
2) Ability to add a Watermark based on groups.
3) Ability to manager permissions based on groups.
A) allow only admins to turn watermarks on and off.
4) Better compatibility with Safari (dragging the image around only works for a few pixels at a go).

I noticed the watermark module is not without bugs, so I just want to make sure I'm not working on features that are already planned/begun.

One bug I noticed in CVS (as of 10/14/2004) :
Hitting save on the "Edit A Watermark" page always results in an error.
Error (ERROR_BAD_PARAMETER) : Controller results are missing status, error or (redirect,delegate)
in main.php at line 172 (gallerystatus::error)
in main.php at line 47
in main.php at line 40

Joseph Elwell.

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Thu, 2004-10-14 22:49

I'm not sure I understand what you want to accomplish with 2, 3 or A. 1 and 4 sound like good ideas.

Can you give more detailed steps to reproduce the bug you mentioned? Does it occur from a clean install? I couldn't create any errors from Edit a Watermark view.

Here are little things I see:
You can give names to watermarks in site admin or user admin.. but in "edit photo" when adding a watermark the listbox still shows the filename I uploaded (with _ instead of .), not the name.
In site admin/user admin you can set a location and which derivatives to watermark.. where are these preferences used? When I go to "edit photo" to add a watermark I make those selections again, and they don't even default to what I set in site admin.

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Thu, 2004-10-14 22:52

A bigger thing:
Watermark a photo, go to site/user admin and delete the watermark.. now go back to the album with the watermarked photo and do rebuild thumbs (or rotate the photo if original is watermarked).. the thumb and/or preferred derivative now show our broken image image.

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7993
Posted: Fri, 2004-10-15 05:07
jelwell wrote:
Hitting save on the "Edit A Watermark" page always results in an error.
Error (ERROR_BAD_PARAMETER) : Controller results are missing status, error or (redirect,delegate)
in main.php at line 172 (gallerystatus::error)
in main.php at line 47
in main.php at line 40

I can't reproduce this, either. I did find a bug where if you add a watermark as one user, then view "Your Watermarks" as another user, it doesn't properly exclude the first user's watermarks. Instead of the image there's an error like "[render error]". I fixed this just now, but it doesn't sound like the error you were seeing.

mindless wrote:
You can give names to watermarks in site admin or user admin.. but in "edit photo" when adding a watermark the listbox still shows the filename I uploaded (with _ instead of .), not the name.

I added a watermark, gave it a name, then went to the "Add Item: From Browser" page and it showed up in the dropdown as the name I gave it, not the filename. Can you tell me the steps to reproduce what you see?

mindless wrote:
In site admin/user admin you can set a location and which derivatives to watermark.. where are these preferences used? When I go to "edit photo" to add a watermark I make those selections again, and they don't even default to what I set in site admin.

Those preferences get used whenever you add a photo via the ItemAddOption (ie, as part of the upload process). You're right -- it should automatically start off at that location if you select "Edit Photo: Watermark" to add a new watermark to an image.

mindless wrote:
Watermark a photo, go to site/user admin and delete the watermark.. now go back to the album with the watermarked photo and do rebuild thumbs (or rotate the photo if original is watermarked).. the thumb and/or preferred derivative now show our broken image image.

Yea. That's a big pain in the butt. The only thing I can think to have us do is that when you delete a watermark it can scan all derivatives to see if it's in use, then remove the watermark from those derivatives. Thoughts?

[edit: fixed the quotes -- thanks mindless!]

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Fri, 2004-10-15 06:04

It was in edit photo / Watermark where I saw the listbox not using the watermark names.. I hadn't looked at the watermark option in add items.

Removing existing watermarks seems like the right thing, as long as the user is warned that watermarks are being removed when they delete the watermark image.

(fyi, quote= requires quotes around the name, for some reason..)

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7993
Posted: Fri, 2004-10-15 06:25
mindless wrote:
It was in edit photo / Watermark where I saw the listbox not using the watermark names.. I hadn't looked at the watermark option in add items.

Got it. Fixed, thanks!

mindless wrote:
Removing existing watermarks seems like the right thing, as long as the user is warned that watermarks are being removed when they delete the watermark image

I've filed two bugs about this: 1047586, and 1047587 so that we don't forget.

 
jelwell

Joined: 2003-05-29
Posts: 115
Posted: Sat, 2004-10-16 20:04

I think I've misunderstood this feature somewhat.

But let me start with the bug.

This is with Safari on the Mac. If I go to the "Site Administration" page for "Watermarks" and I click on "edit" in the Action column of one of my watermarks I get sent to the "Edit A Watermark" page. If I just leave the defaults and click on the "Save" button, I get an error on the next page:

Error (ERROR_BAD_PARAMETER) : Controller results are missing status, error or (redirect,delegate)
in main.php at line 172 (gallerystatus::error)
in main.php at line 47
in main.php at line 40

On Internet Explorer (on the Mac) when I get to the "Edit A Watermark" page there's not even a "Save" button, nor a "Cancel" button. *shrug* This isn't so important to me since I only fired up Internet Explorer because I thought it might be a browser issue.

On Camino hitting save doesn't cause any problems. But then I can't drag the watermark at all.

I'll work on these compatibility issues for now.

As for me not understanding the module, the whole component simply doesn't seem to work (under Safari), so I was just guessing at the functionality. Anyways, what I want to do - in particular - is add systemwide watermarks to images that are loaded outside of the Gallery framework. That means if someone embeds a gallery image into another website the image will be automatically watermarked. Groups come into play because I want to set it up to watermark or not based on whether the owner is in a certain group. Anyways, I can handle all this code myself, I was just trying to figure out if these kind of features are something you'd want integrated into this module. I'm going to hold off on this work until I can figure out the Safari issues.
Joseph Elwell.

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7993
Posted: Tue, 2004-10-19 06:54

The DHTML library we're using for our drag and drop routines claims compatibility with Safari. Unfortunately, Safari is failing to even launch on my OSX box right now (it crashes immediately -- doh) so I can't do any testing yet. When I get Safari fixed, I'll look into this further. If you make any progress, let me know.

As for the way that it's supposed to work -- I didn't intend it the way that you're hoping. As it is, the watermarking module will watermark your images inside G2 and will show the watermarked version to everybody. I'd be happy to work with you on your own version of the watermarking module, though. Catch me on #gallery and let's chat sometime.

 
fryfrog

Joined: 2002-10-30
Posts: 3236
Posted: Tue, 2004-10-19 08:26

I like his idea of a feature to only watermark images that are hotlinked. That would be groovey. Btw, since g2 does image firewalling... how WOULD you hotlink if you wanted to?

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Tue, 2004-10-19 15:25

you can still grab the url for the image itself and use it in other web pages, if the image has permission for Everybody group.

 
baschny
baschny's picture

Joined: 2003-01-04
Posts: 328
Posted: Tue, 2004-10-19 16:07

fryfrog, you would have to check the request referrer ($_SERVER["HTTP_REFERER"]) if it comes from your site or from an unknown site and do the switch. I think it could be an interesting feature.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2004-10-19 16:24
fryfrog wrote:
I like his idea of a feature to only watermark images that are hotlinked.

Ernst wrote:
fryfrog , you would have to check the request referrer ($_SERVER["HTTP_REFERER"]) if it comes from your site or from an unknown site and do the switch. I think it could be an interesting feature.

That feature would be great.
In the config view of the feature you can add/remove domains/urls which can hotlink the picture without watermarks, you could set different watermarks / domain etc.

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Tue, 2004-10-19 16:54

I accomplished this with a patch to modules/core/DownloadItem.inc:

$path = $data['derivativePath'];
$mimeType = $data['mimeType'];
if (!isset($_SERVER['HTTP_REFERER']) || strpos($_SERVER['HTTP_REFERER'], 'mydomain.com') === false) {
  // Bad referer.. watermark the image:
  list ($ret, $toolkit) = GalleryCoreApi::getToolkitByOperation($mimeType, 'composite');
  if ($ret->isError()) {
    return array($ret->wrap(__FILE__, __LINE__), null);
  }
  if (!isset($toolkit)) {
    return array(GalleryStatus::error(ERROR_PERMISSION_DENIED, __FILE__, __LINE__), null);
  }
  $tmpFile = $platform->tempnam($gallery->getConfig('data.gallery.tmp'), 'wmk_');
  list ($ret, $mimeType) = $toolkit->performOperation(
    $mimeType, 'composite', $path, $tmpFile, array('watermark/watermark_png', 'image/png',
                                                   96, 39, 'bottom-right', 0, 0));
  if ($ret->isError()) {
    return array($ret->wrap(__FILE__, __LINE__), null);
  }
  $path = $tmpFile;
}

...

if (isset($tmpFile)) {
  @$platform->unlink($tmpFile);
}

This is in renderShortcut().. then I changed a few more lines to use $path and $mimeType where appropriate. Similar code is needed in renderImmediate() so the same logic applies when the permissions aren't already cached. You can see above that I hardcoded the parameters for the watermark... with this code in place I can browse my G2 fine, but if I do "view image" in mozilla for anything I see the image with a watermark (mozilla doesn't send any referer when you do "view image").
The referer check could be a little more robust, so other websites can't put their page at theirdomain.com/mydomain.com/page.php.. ;) It should probably also check that it's working with an image.. for other items types my code above will give PERMISSION_DENIED because it won't find a toolkit that can apply 'composite' to movies, mp3s, etc

I'm not sure how the same can be accomplished in a module...

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7993
Posted: Tue, 2004-10-19 18:57

Hey, that's pretty cool. The performance won't be great, but I bet if we turn this into a separate module we can introduce a module specific cache just for this. I created a task for this.

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Tue, 2004-10-19 21:44

yeah, I thought the same about caching.. either by managing its own file cache or by creating actual DerivativeImage entities. (I also figured, who cares if it's slow for someone using my images on their site!) Using derivatives is probably better since it will automatically benefit from cache expiration if the source is modified.

but, how can this fit in as a module? the only code the runs before renderShortcut() is GalleryUrlGenerator::parseCurrentUrl().. (for mapping short urls to the right view).

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Tue, 2004-10-19 23:24

Another watermark bug: ItemAdd doesn't check the mime type before applying the watermark you select.. ie, try uploading a pdf and pick a watermark to apply.. it goes ahead and creates a preferred derivative. I already filed a bug for this.

 
jelwell

Joined: 2003-05-29
Posts: 115
Posted: Tue, 2004-10-19 23:52

Keep in mind there's Gallery 1 code for preventing deep linking, with caching already. Don't know if that will help, it includes code for watermarking with Text instead of an image. But I'm sure you all know that already. ;)

http://gallery.menalto.com/index.php?name=PNphpBB2&file=viewtopic&p=55547#55547

http://gallery.menalto.com/index.php?name=PNphpBB2&file=viewtopic&t=12926&highlight=htaccess

As for the Safari issue, I emailed the author of the library. I don't know how much can be done to support Safari. The issue is, in particular, with dragging images. Safari lets you download an image from a website by dragging the image from Safari and dropping on your desktop. So after a few pixels of movement the image "comes off the page" and the javascript library stops registering the drag.

My suggestion to the library author was to add a dhtml div (for Safari only) to pure image divs that's sort of a border, that allows for dragging in Safari. If I don't hear from the author I might try to add this, but it's not terribly important for me, since I don't intend on installing any watermarking module other than a site admin utility to deal with deep linking.
Joseph Elwell.

 
saul11

Joined: 2005-10-04
Posts: 109
Posted: Sat, 2006-01-21 16:37

I've added a small feature to the watermark module:
On the watermarkEdit page you can now choose different background colors for the Placement layer. And I've set a default backgroundimage so the default background looks like a grid (like photoshop).
To install this feature overwrite, or put in a 'local' folder, the WatermarkEdit.tpl file and create an 'images' directory in your watermark module with 'backgroundGrid.gif'.
(For the grid to fit perfectly, I've increaed the height of the layer a bit to 304px)

 
saul11

Joined: 2005-10-04
Posts: 109
Posted: Sun, 2006-01-22 09:02

mindeless,
Could you please help me extending the watermark module so that an album can have a watermark assigned to it? Now only individual photos can get watermarks. My goal is to just upload photos, for example by using the publishXP method, and have the watermarks assigned to the photos. I haven't got a clue where to start, so any help greatly appreciated!

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Sun, 2006-01-22 16:17

you'll probably want to change the itemeditplugin to appear for albums as well as data items; when used for an album it uses a plain background instead of image background for watermark placement. when used for an album it saves the resulting composite parameters in a plugin parameter for the album's id. then you need to modify the itemaddoption for watermark to check that pluginparameter and apply the watermark if found.

 
saul11

Joined: 2005-10-04
Posts: 109
Posted: Sun, 2006-01-22 22:30

I've been trying to implement this with help from #gallery@IRC, but then valiant told me that it existed already in the latest nightly build Gallery 2.1 (Blackjack). And indeed in the changes highlist is "PublishXP module now supports add-options such as watermarks and applying size limits or quotas."

I'm a happy user now, instead of a developer wannabee with a headache :)

 
bluemamba

Joined: 2006-07-22
Posts: 3
Posted: Tue, 2006-07-25 23:27

The greatest "bug" in this module is it's incapacity of watermaking an entire album right from the gallery.
This "bug" really makes me sad an makes me thinking on switching back to Coppermine :(
Still, it's a wonderfull gallery ... that misses one of the photographer's essential needs: 100% automatic watermaking :(

Pozehaioase.ro