Watermarking hack (w/ ImageMagick) - Page 3 Watermarking hack (w/ ImageMagick) - Page 3
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

Watermarking hack (w/ ImageMagick)

Started by flex, November 10, 2003, 11:50:10 PM

Previous topic - Next topic

0 Members and 3 Guests are viewing this topic.

comic

Quote from: "flex"As for thumbnails, I didn't see much point in watermarking them since they are tiny and I can't imagine anyone would want to copy the thumbnail.

Well, I've two reasons to do so:

1) My watermark is a text with the siteaddress; I use the thumbnails on another site for publicity
2) When you look at the properties of a thumnail, it's far too easy to download the full non watermarked original . . . (just remove the "thumb_" part and load the rest of the url in your browser)

Hope you reconsider to take a look for me (I solved it partly as stated above, but the solution is incomplete).

thanks!,
pieter

flex

Well I understand the security point of view, and that has been on my mind since I created the watermark hack. The only way I can see round this is to place the whole album directory outside of the web root so it's impossible to access them via a browser, yet the scripts can still access them to watermark & output them.

Just thinking about this now, I have no idea what effect this would have on the rest of the coppermine code, I'm not entirely sure if it's as simple as setting up your config files/options and changing the location of the albums directory. However, I imagine that it is possible. Also, not all webhosts let you put things outside the web root.

But if you'd like thumbnails watermarked as well, just change this code:

      if((($mode == "normal") || ($mode == 'fullsize')) && ($CONFIG['thumb_method']=='im')){

      // return the url to the wm script
      return "wm.php?pid=".$pic_row["pid"]."&mode=".$mode;

   }else{
      // it's a thumb, don't bother wm'ing
      return $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);

   }


to this:


     
if($CONFIG['thumb_method']=='im'){

    // return the url to the wm script
    return "wm.php?pid=".$pic_row["pid"]."&mode=".$mode;

}else{
    // ok so we're not using ImageMagick, so can't wm it...
    return $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);

}


I've not tested that, but it should work as it's just taking out a couple of the if clauses. Test it and let me know.

I also looked into the possibility of using seperate watermark images for each of the 'normal', 'thumb' and 'fullsize' images since I think the wm should be scaled for each one of these... Let me know if you'd like me to look into that, shouldn't be difficult to do...

Cheers,
Flex :)

comic

Quote from: "flex". . . The only way I can see round this is to place the whole album directory outside of the web root so it's impossible to access them via a browser, yet the scripts can still access them to watermark & output them.

Interesting idea . . . anyone has experiance with this?

Quote from: "flex"But if you'd like thumbnails watermarked as well, just change this code:

     
if($CONFIG['thumb_method']=='im'){

    // return the url to the wm script
    return "wm.php?pid=".$pic_row["pid"]."&mode=".$mode;

}else{
    // ok so we're not using ImageMagick, so can't wm it...
    return $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);

}


I've not tested that, but it should work as it's just taking out a couple of the if clauses. Test it and let me know.

I also looked into the possibility of using seperate watermark images for each of the 'normal', 'thumb' and 'fullsize' images since I think the wm should be scaled for each one of these... Let me know if you'd like me to look into that, shouldn't be difficult to do...

I did a similar change before, but found that sometimes ($pic_row["pid"] == "") and therefore the wm.php didn't give a picture back. I modified the code for thumnails as follows:


if((($mode == "normal") || ($mode == 'fullsize')) && ($CONFIG['thumb_method']=='im')){

// return the url to the wm script
 return "wm.php?pid=".$pic_row["pid"]."&mode=".$mode;

}else{
// it's a thumb, if possible do wmt'ing (wmt.php has the same code as wm.php, but calls smaller watermark)
 if ($pic_row["pid"] == ""){

 $url_thmbnl = $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);

  return $url_thmbnl;

 }else{

  return "wmt.php?pid=".$pic_row["pid"]."&mode=".$mode;

 }


Everyone wanting to use this, please note that my code doesn't check correctly for imagemagick (because I only use imagemagick ;))

Problem remains that in album list the pictures will not be watermarked and the properties still show the filename, so these files can still be downloaded. Here's and example: http://www.comictoys.info/cpg/index.php?cat=2 . Rightcliking gives the properties of these pictures. I know how to prevent rightclicking, but that will only hold off newbies. Now if you click on one of the pictures there, you will see that all other thumbnails ARE watermarked! This is because of the code I listed above.

Pieter

Joachim Müller

@comic: if you're the only one uploading to your gallery, why don't you attach the watermark client sided (before upload)? There are some good free programs out there that do this in no time.

GauGau

comic

Quote from: "gaugau"@comic: if you're the only one uploading to your gallery, why don't you attach the watermark client sided (before upload)? There are some good free programs out there that do this in no time.

Every registered member, is allowed to upload . . .  :P

Besides . . . having coppermine do it for me, takes less time

but thanks anyway for trying to help

flex

I don't know why $pic_row["pid"] would ever return an empty string since every photo *should* (and is required by the database structure) to have a unique ID for each photo, pid.

The only reason why I'd think that you wouldn't get a returned watermark image is if the fullsize image has dimensions below what you specify as the intermediate image (which I don't think my script checks for). There are some alterations which I could do to the script to check for this...

Without looking at your gallery I can't say for sure...

comic

Quote from: "flex"I don't know why $pic_row["pid"] would ever return an empty string since every photo *should* (and is required by the database structure) to have a unique ID for each photo, pid.

I'm afraid it does and saw another script that tried to hide the url of the pictures do a check on the $pic_row["pid"]. That script also returned the real url for a thumbnail when it was empty.

Quote from: "flex"The only reason why I'd think that you wouldn't get a returned watermark image is if the fullsize image has dimensions below what you specify as the intermediate image (which I don't think my script checks for). There are some alterations which I could do to the script to check for this...

Without looking at your gallery I can't say for sure...
The example I gave in my previous post only contains pictures with 1200x1600 resolution, while intermediate is 500 pixels. If you follow one of the pictures in the albumlist you'll notice the same thumbnail is in the gallery and that at that point the watermark DOES work! So I guess the check is not the solution. . .

Quote from: "Comic"Problem remains that in album list the pictures will not be watermarked and the properties still show the filename, so these files can still be downloaded. Here's and example: http://www.comictoys.info/cpg/index.php?cat=2 . Rightcliking gives the properties of these pictures. I know how to prevent rightclicking, but that will only hold off newbies. Now if you click on one of the pictures there, you will see that all other thumbnails ARE watermarked! This is because of the code I listed above.

flex

I think I might know what the problem is. I'll download the coppermine source again and take a second look. I'll post back here if/when I find the solution.

Flex :)

FreeMail

any tip on how to create our own watermark text or graphics?  via photoshop.


tia!

golf16vkr

Thanks this hack worked excellent for me

FreeMail

hi!  i have this problem, cant seem to find my INCLUDES folder on my Harddisk, but its on my WEBSERVER.  inside the INCLUDES folder is the functions.php file not the functions.inc.php as stated in the 1st post by FLEX.

please clarify, thanks!

TIA!

flex

I'm guessing that depends on what version of coppermine you're using. Anything above version 1.1 i think it'll be called functions.inc.php, but anything before that I don't know...

As for tips on creating the watermark image, it needs to be a png called watermark.png. If you want transparency then you'll need to create an alpha channel layer in photoshop to do this. I think you do this in the layer window, but I can't remember the exact process to do it. Maybe look in the photoshop help for 'alpha channels' or google it?

You can load my watermark (http://www.jvcam.co.uk/coppermine/watermark.png) into photoshop to see how mine looks and go from there?

Flex :)

flex

Ok I've created a generic coppermine watermark for those having trouble creating one in photoshop/paintshop pro and don't want to use the one I posted (obviously).

I'm still looking at the thumbnail watermark problem.. just takes a while for my head to get round the code again.

Here's the generic watermark:
http://www.jvcam.co.uk/coppermine/watermark-cpg.png

You'll need to rename it to watermark.png for it to work with the script.[/php]

FreeMail

i have both include and includes in my server.  the include folder is where i have functions.inc.php, thats the file i should edit?

flex

functions.inc.php is the file u should edit

FreeMail


FreeMail

got this error message :(

QuoteParse error: parse error in /home/ast/public_html/include/functions.inc.php on line 1109

Fatal error: Call to undefined function: get_pic_url() in /home/ast/public_html/index.php on line 462

flex

Umm, u did edit the file right? not just replace the contents of it with what the post says?

FreeMail

my index.php page is working already, but clicking the normal picutre give my a X.

bshrdr

Well, I took this cool little hack a step further.  Instead of creating a PNG offline (which was no real problem - it just didn't suit my needs), I wanted to just use plain old text.  So I came up with this, which creates a small PNG on the fly.  It puts out 2 layers of text - a foreground and a shadow offset by one pixel to the right and down, then mashes it to the requested image, as the original script did.

Just find this in wm.php:

$cmd = "{$CONFIG['impath']}composite -compose over -gravity Southeast \"".realpath("./watermark.png")."\" \"".realpath('./'.$CONFIG["fullpath"].$row["filepath"].$pic_prefix[$mode].$row["filename"])."\" jpg:-";


And replace it with this:


            $line1 = "Line One Text Here";
            $line2 = "Line Two Text Here";
            $home = "/full/path/to/CPG/home/";  #with trailing slash
            $im = imagecreate(180,35);     #Modify for size of image you wish
            $bg = imagecolorallocatealpha($im,255,255,255,127);  #sets background color as white & transparent
            $textcolor = imagecolorallocate($im,0,0,0);  #foreground text color
            $textcolor1 = imagecolorallocate($im,255,255,0);  #shadow text color
            imagestring($im,3,1,1,$line1,$textcolor1);
            imagestring($im,3,0,0,$line1,$textcolor);
            imagestring($im,5,2,13,$line2,$textcolor1);
            imagestring($im,5,1,12,$line2,$textcolor);
            imagepng($im,$home."wmark.png");

            $cmd = "{$CONFIG['impath']}composite -compose over -gravity Southeast \"".$home."wmark.png\" \"".realpath('./'.$CONFIG["fullpath"].$row["filepath"].$pic_prefix[$mode].$row["filename"])."\" jpg:-";


One caveat - you may need to create the temporary wmark.png file in the root CPG directory with 777 permissions prior to running the script.  Just create a zero length file, and the script will create it the first time it runs.

It's in use on my CPG site - http://photos.railfanzone.com (still in development, but almost there...)

Enjoy!
Tom