ok here it is, it'll probably need some fixes. I've listed the known issues at the bottom:
Step 1. includes/functions.inc.phpFind this line right at the bottom of the script:
return $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);
And change it to this:
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']);
}
Step 2. Create a new file in the coppermine root dir called wm.php:<?
define('IN_COPPERMINE', true);
require('include/init.inc.php');
header('Content-Type: image/jpeg');
header('Content-Disposition: inline; filename=file.jpg');
$pid = $_REQUEST["pid"];
$mode = $_REQUEST["mode"];
$sql = "SELECT * FROM ".$CONFIG['TABLE_PREFIX']."pictures WHERE pid=$pid";
$db = mysql_connect($CONFIG['dbserver'], $CONFIG['dbuser'], $CONFIG['dbpass']);
mysql_select_db($CONFIG['dbname'], $db);
$result = mysql_query($sql, $db);
$row = mysql_fetch_array($result);
$pic_prefix = array(
'thumb' => $CONFIG['thumb_pfx'],
'normal' => $CONFIG['normal_pfx'],
'fullsize' => ''
);
$cmd = "{$CONFIG['impath']}composite -compose over -gravity Southeast \"".realpath("./watermark.png")."\" \"".realpath('./'.$CONFIG["fullpath"].$row["filepath"].$pic_prefix[$mode].$row["filename"])."\" jpg:-";
passthru ($cmd, $output);
echo $output;
?>
Make sure you watch those line breaks when copying & pasting as it seems to have broken up some of them cos of page width etc.
Step 3. Get a copy of watermark.pngGet my one from here:
http://www.jvcam.co.uk/coppermine/watermark.pngAnd put it in your root coppermine directory.
Known Issues1. Images stored on other servers, I've not even looked at how coppermine handles this but I know it does from looking at the code, but this doesn't support that and I'm not sure it would be possible for imagemagick to do it anyway with remote images.. Thinking it would take some php code to retrieve the image, wm it and then display it - I guess it's possible.
2. GD. GD implementation I've not even looked at yet, I don't know if it's possible but I'll try have a look in the next couple of days and see if it's possible. That said, if you're using GD, then it shouldn't effect the way you use coppermine, it just won't watermark the images.
3. At present there's no way to turn it on or off through the config screen, this is something the other dev's can do easily I'm sure, I didn't get stuck into the config stuff. The only way you can turn it off is to remove the altered script lines. Also, it watermarks both 'normal' and 'fullsize' images, there's no option to turn either one on/off yet.
4. Versions. It should work in anything greater than coppermine 1.1, since that's what I tested it with and I checked the 1.2 code and there's no changes in the lines I altered.
5. I'll try and produce a tutorial in creating the watermark images because it's not exactly straight forward and it has to be a png file. I couldn't get transparent gifs to work at all.
6. Server load. I've no idea how much server load it takes to wm an image every time it's requested as I don't have full access to the server I work on... Anyone who does have access and can check, I'd be interested to see how much load it creates.
I corrected it so that it doesn't pass the full url to the wm.php script, it now uses the pid of the image to find it and look it up in the db. This should somewhat stop people from stealing your images by finding the full path but it's not infallable.
I'm sure there's a few other issues too that I'm not aware of so I encourage people to try it out and see what happens and report back to this thread.
Last note, the wm image I use is this one
http://www.jvcam.co.uk/coppermine/watermark.pngThose with photoshop can check it out to see how it works.
Good luck!
- Flex
