singapore: the smallest big galery
home » forum » Mods » Watermarking

You are not logged in.

#1 2006-02-23 22:25:19

Paul
Member

Watermarking

I found somewhere on here a little function for watermarking images (by grantangi) which works marvellously for watermarking thumbnails, since he told me to put the line

Code:

$thumb = sgThumbnail::markImage ($thumb,'(c) Joe Bloggs');

into thumbnail.class.php.

Is there a way to do this for full-sized images? Is there some bit of code somewhere which recognises a 'new' image (newly uploaded) which I can hijack slightly to watermark before it is displayed?

(I guess it needn't be a new image - the watermark could be added every time the image is displayed).

Thanks.

Last edited by Paul (2006-02-23 22:25:55)

Offline

 

#2 2006-02-24 01:05:45

pavian
Moderator

Re: Watermarking

well no, since you are viewing the real fullsize image, as it is uploaded. If you however force a special width on the big image, your little watermarking thing should work as on every thumbnail

Offline

 

#3 2006-02-24 01:27:47

Paul
Member

Re: Watermarking

Right, thanks.

So, conceivably, I could take every image, force a resize upon it - but resize it to its original size - add my watermark, and then display it?

Which file would I have to hack in v.0.10 to get this to work? I haven't gotten to grips with these files yet (I can barely manage PHP!)

Offline

 

#4 2006-02-24 07:19:30

grantangi
Member

Re: Watermarking

Paul wrote:

Which file would I have to hack in v.0.10 to get this to work? I haven't gotten to grips with these files yet (I can barely manage PHP!)

I modified the function imageHTML in image.class.php to point to thumbnailHTML:

Code:

$ret = $this->thumbnailHTML ($class, 'image');

In this function the thumbnail function is called...now with the type image...which uses the options ending in image from your template.ini file...which are set to the maximum width or height of the image (in my case 600):

Code:

thumb_width_image  = 600
thumb_height_image = 600
thumb_force_size_image = off

I'm not sure if this is all that is needed...as I modified the code in some places (always trying to keep to the original when possible)...but it is the basic idea...

  Udo

Offline

 

#5 2006-03-02 04:50:25

tamlyn
Lead Developer

Re: Watermarking

You need to hack a little more in order to force thumbnails to be created even if the image is already small enough: comment out the stuff around line 60-65 of thumbnail.class.php.

You shouldn't need to edit imageHTML() since the thumbnail is already returned automatically if full_image_resize is on.

Also the thumb_force_size_* options were renamed to thumb_crop_*

Offline

 

#6 2006-03-10 23:52:16

Paul
Member

Re: Watermarking

Thanks for everyone's help on this matter. I've finally got it sorted out! Woohoo! (Please don't ask me how I did it, though...)

It seems like a relevatively simple thing which could be easily incorporated into the next release, perhaps?

Offline

 

#7 2006-03-13 18:07:23

Hajduk
Member

Re: Watermarking

LOL, well I would like to ask how you did it :-p
Can anyone explain from the beginning a retards guide in steps on what and where to edit exactly.

Muchos gracias

Offline

 

#8 2006-03-13 18:23:05

Paul
Member

Re: Watermarking

Darnit! wink

I'm using version 0.10.0PRE2.

Okay, so first I used the excellent little function created by Udo:

Code:

  function markImage ($img, $waterMark)
  {
    $tmp_img = $img;

        $black = @imagecolorallocate ($tmp_img, 0, 0, 0);
        $white = @imagecolorallocate ($tmp_img, 255, 255, 255);

        $originx = imagesx ($tmp_img) - 105;
        $originy = imagesy ($tmp_img) - 20;
        @imagestring ($tmp_img, 2, $originx + 10, $originy, $waterMark, $black);
        @imagestring ($tmp_img, 2, $originx + 11, $originy - 1, $waterMark, $white);

        return ($tmp_img);
  }  // markImage

I put this into thumbnail.class.php right at the top, just under the line var $thumbPath = "";

Then I commented out the following lines (lines 76-80, now), in the same file, as Tamlyn suggested. This creates a new thumbnail every time:

Code:

    //link straight to image if it smaller than required size
    if($this->image->width <= $this->thumbWidth && $this->image->height <= $this->thumbHeight) {
      $this->thumbPath = $this->image->imageURL();
      return;
    }

Then, just under where it sets the image interlacing (line 219 in my code), I wrote:

Code:

        if ($this->thumbWidth > 101) {
                $thumb = sgThumbnail::markImage ($thumb, '(c) Paul');
        }

So this means that only my 'large' images get watermarked (since my thumbnails aren't bigger than 100px). If you do want your thumbnails watermarked too, then just strip off the first and last lines of that, leaving $thumb = SgTh... etc.

And that's pretty much it. You may have to fiddle with the image resizing feature in singapore.ini and your particular template.ini. I'm not sure that's crucial, though.

Last edited by Paul (2006-03-13 18:25:52)

Offline

 

#9 2006-03-16 22:58:13

Paul
Member

Re: Watermarking

As an addendum, if you don't want to hardwire in your watermark text, you could use something like:

Code:

'(c) '.$this->image->artist

in the markImage function call for more flexibility. This would require you to supply an artist name for each image, though.

Last edited by Paul (2006-03-16 23:03:43)

Offline

 

#10 2006-03-17 00:28:50

tamlyn
Lead Developer

Re: Watermarking

better to use the accessor method $this->image->artist() rather than accessing the property directly because at some point we'll be implementing metadata inheritance so you can set the artist on the root gallery or any other gallery and everything within it will then have artist (or whatever) set.

Offline

 

#11 2006-03-26 15:23:05

Lemmontree
Member

Re: Watermarking

Can you pls post the code for 0.9X to create a watermark on a thumbnail?

Offline

 

#12 2006-03-26 17:25:58

Paul
Member

Re: Watermarking

Did you try the code above? It seems to me it should be okay with v.0.9(.11)... just the line numbers will be different. And thumbnail.class.php was called thumb.php, I think.

Offline

 

#13 2006-03-26 22:46:43

Gary
Guest

Re: Watermarking

Here's a slightly modified version that uses a TrueType font instead of plain text. I wanted clearer text and a nice copyright symbol. Also, there are four "shadow" layers to provide easier readbility on light colored images.

Code:

function markImage ($img, $waterMark)
  {
    $tmp_img = $img;

        $black = @imagecolorallocate ($tmp_img, 0, 0, 0);
        $white = @imagecolorallocate ($tmp_img, 255, 255, 255);

        $text = '© Your name here';        
        $originx = imagesx ($tmp_img) - 150;
        $originy = imagesy ($tmp_img) - 20;
    $font = "/xxxx/xxxxxxx/public_html/includes/arial.ttf";
    @imagettftext($tmp_img, 11, 0, $originx + 11, $originy, $black, $font, $text);
    @imagettftext($tmp_img, 11, 0, $originx + 9, $originy, $black, $font, $text);
    @imagettftext($tmp_img, 11, 0, $originx + 10, $originy + 1, $black, $font, $text);
    @imagettftext($tmp_img, 11, 0, $originx + 10, $originy - 1, $black, $font, $text);
    @imagettftext($tmp_img, 11, 0, $originx + 10, $originy, $white, $font, $text);
    
        return ($tmp_img);
  }  // markImage
 

#14 2006-03-26 22:47:36

Lemmontree
Member

Re: Watermarking

ah ok and where in the thumb.php?

Offline

 

#15 2006-03-26 22:51:18

Gary
Member

Re: Watermarking

Whoops, line 8 should read:

Code:

$text = '© Your name here';

corrected as you mentioned - pavian

Last edited by pavian (2006-03-27 17:51:05)

Offline