Advanced search  

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Pages: [1] 2 3 4 5 6   Go Down

Author Topic: Watermarking hack (w/ ImageMagick)  (Read 210128 times)

0 Members and 1 Guest are viewing this topic.

flex

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 29
Watermarking hack (w/ ImageMagick)
« on: November 10, 2003, 11:50:10 pm »

Hi there,

I just knocked up a quick hack to use water marking for coppermine. Check it out here: http://www.jvcam.co.uk/coppermine/

It doesn't alter any image on the server, just overlays the image every time a fullsize or normal image is requested (on-the-fly). It uses the 'composite' function of imagemagick but i think you can use a few of the others too to do the same thing. I'm no imagemagick expert.

The watermark image itself is a PNG file created in photoshop with alpha-layer transparency, you can find the one i use here: http://www.jvcam.co.uk/coppermine/watermark.png

If anyone's interested in the code, I'll try tidy it up and make it work for other people too.

I'm guessing that configuration could be put into coppermine to specify where the watermark is placed etc.

Before I tidy up the code, the imagemagick command I use is:

Code: [Select]
composite -compose over -gravity Southeast '".realpath("./watermark.png")."' '/home/users/jonny/www.jvcam.co.uk/html/coppermine/albums/$p' jpg:-

Obviously that's somewhat specific to my server cos I've not used any of the config includes from coppermine yet.

Anyways, enjoy :)

[edit]
It uses the full path of the image to pass to wm.php to get the image, but really this should use the db pid of the picture else it's not exactly secure.. but this is just a quick hack, i'll change it before i post the code ;)
[/edit]
« Last Edit: August 25, 2004, 08:45:16 pm by GauGau »
Logged
jvcam.co.uk

moorey

  • VIP
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 404
Re: Watermarking hack
« Reply #1 on: November 11, 2003, 02:33:00 am »

Quote from: "flex"

If anyone's interested in the code, I'll try tidy it up and make it work for other people too.


That would be great! Excellent work.
Logged

DefenceTalk.com

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 230
    • http://www.defencetalk.com
Watermarking hack (w/ ImageMagick)
« Reply #2 on: November 11, 2003, 04:10:02 am »

Who isn't interested in watermarking tool? I am!! I tried this another php based watermark tool... but i couldn't make it work!  :cry:

Only works with imagemagic???
Logged
(http://www.defencetalk.com/pictures/signature_cpg.php)

flex

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 29
Watermarking hack (w/ ImageMagick)
« Reply #3 on: November 11, 2003, 12:59:05 pm »

ok here it is, it'll probably need some fixes. I've listed the known issues at the bottom:


Step 1. includes/functions.inc.php

Find this line right at the bottom of the script:
Code: [Select]

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


And change it to this:

Code: [Select]

        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:

Code: [Select]
<?
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.png

Get my one from here:
http://www.jvcam.co.uk/coppermine/watermark.png

And put it in your root coppermine directory.

Known Issues
1. 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.png
Those with photoshop can check it out to see how it works.

Good luck!

- Flex :D
Logged
jvcam.co.uk

moorey

  • VIP
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 404
Watermarking hack (w/ ImageMagick)
« Reply #4 on: November 12, 2003, 01:46:19 am »

Thanks, flex!
FYI, moved this to the MOD section..
Logged

DJMaze

  • VIP
  • Coppermine addict
  • ***
  • Offline Offline
  • Posts: 831
    • Dragonfly CMS
Watermarking hack (w/ ImageMagick)
« Reply #5 on: November 12, 2003, 03:49:16 am »

Using GD is damn easy: http://www.php.net/manual/en/function.imagecopymerge.php

imagecopymerge combines 2 images and you can even setup a X and Y

And rotate it http://www.php.net/manual/en/function.imagerotate.php
Logged
There are 2 kinds of users in this world: satisfied and complainers.
Why do we never hear something from the satisfied users?
http://coppermine-gallery.net/forum/index.php?topic=24315.0

flex

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 29
Watermarking hack (w/ ImageMagick)
« Reply #6 on: November 12, 2003, 12:42:42 pm »

Yeh I had a look yesterday at GD but my server is playing up saying it's running out of memory when using createimagefromjpeg(), not sure what's up with that. Thought it was my code to start with but I tried switching coppermine to GD 1 or 2 and I get the same probs :\

Getting this error message:

Fatal error:  Allowed memory size of 8388608 bytes exhausted (tried to allocate 6400 bytes) in /home/users/jonny/www.jvcam.co.uk/html/coppermine/wm2.php on line 26
Logged
jvcam.co.uk

DJMaze

  • VIP
  • Coppermine addict
  • ***
  • Offline Offline
  • Posts: 831
    • Dragonfly CMS
Watermarking hack (w/ ImageMagick)
« Reply #7 on: November 12, 2003, 01:11:29 pm »

It seems a lot of servers have this problem.
A jpg is converted to a truecolor GD bitmap when imported.
It seems this uses a lot of memmory or is even a bug.

http://www.php.net/manual/en/function.memory-get-usage.php is a new function since php 4.3.2 check if you can use it and trace the allocated memsize for php tha will maybe give a solution.
Logged
There are 2 kinds of users in this world: satisfied and complainers.
Why do we never hear something from the satisfied users?
http://coppermine-gallery.net/forum/index.php?topic=24315.0

flex

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 29
Watermarking hack (w/ ImageMagick)
« Reply #8 on: November 12, 2003, 01:24:31 pm »

I used phpinfo() to check the memory allocation for PHP, and it's only 8mb. Which I'm guessing is not enough for the images I'm using to test watermarking, 1600 x 1200.

Unfortunately I can't change the amount of memory allocated for PHP as I don't have that kind of access to the server :\
Logged
jvcam.co.uk

DJMaze

  • VIP
  • Coppermine addict
  • ***
  • Offline Offline
  • Posts: 831
    • Dragonfly CMS
Watermarking hack (w/ ImageMagick)
« Reply #9 on: November 12, 2003, 01:30:17 pm »

well hack yeah that kind of image uses a lot of memory, try to reduce the color use when opening in GD the function is in image functions list of php.net
Logged
There are 2 kinds of users in this world: satisfied and complainers.
Why do we never hear something from the satisfied users?
http://coppermine-gallery.net/forum/index.php?topic=24315.0

DJMaze

  • VIP
  • Coppermine addict
  • ***
  • Offline Offline
  • Posts: 831
    • Dragonfly CMS
Watermarking hack (w/ ImageMagick)
« Reply #10 on: November 12, 2003, 07:21:47 pm »

What i realy mentioned with the new memory_get_usage() function is:
Code: [Select]
echo memory_get_usage();
createfromjpeg();
echo memory_get_usage();


This way we can trace how much memory is actualy needed for the image.
Logged
There are 2 kinds of users in this world: satisfied and complainers.
Why do we never hear something from the satisfied users?
http://coppermine-gallery.net/forum/index.php?topic=24315.0

flex

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 29
Watermarking hack (w/ ImageMagick)
« Reply #11 on: November 12, 2003, 08:41:21 pm »

The thing is with the error, is that it's a fatal error message so nothing gets processed after imagecreatefromjpeg. So even trying echo memory_get_usage(); doesn't work :\

Is there an actual fix? Cos I don't see why GD should just fail on a image that size, it's not like it's that massive in terms of digital camera photos.
Logged
jvcam.co.uk

terrorhawk

  • Contributor
  • Coppermine regular visitor
  • ***
  • Offline Offline
  • Posts: 61
Watermarking hack (w/ ImageMagick)
« Reply #12 on: November 13, 2003, 05:51:08 pm »

Hi there..

i was trying to add the watermark hack but when it wants to open the pic in full size (so not the thumpnail) i get a X (image not found).
and i dont have any iedea what this could be.

please help..
if you need the files i changed just ask and i mail
Logged

flex

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 29
Watermarking hack (w/ ImageMagick)
« Reply #13 on: November 13, 2003, 07:37:51 pm »

If you could email me your changed files then I can have a look, email them to jonny (at) jvcam (dot) co (dot) uk

I'll check them and see what's up with them. It could be possible that your installation of imagemagick on your server doesn't have the 'composite' command installed, but I don't think this is likely.

I await your email :)
Logged
jvcam.co.uk

hardlocke

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 35
Watermarking hack (w/ ImageMagick)
« Reply #14 on: November 14, 2003, 12:36:40 am »

hi
i use the watermark-hack from "DJ AXION".... it's great!

- Link to Thread in the old board
- Sample
Logged

terrorhawk

  • Contributor
  • Coppermine regular visitor
  • ***
  • Offline Offline
  • Posts: 61
Watermarking hack (w/ ImageMagick)
« Reply #15 on: November 14, 2003, 10:00:40 am »

Quote from: "flex"
It could be possible that your installation of imagemagick on your server doesn't have the 'composite' command installed, but I don't think this is likely.

I await your email :)


it is possible couse i run it at my own server. sow also i can check what the cpu load will be and memory load but it has to working first..

i will mail it today to you
Logged

flex

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 29
Watermarking hack (w/ ImageMagick)
« Reply #16 on: November 14, 2003, 11:27:13 am »

Can you send me the link to your gallery too? I had a quick look at the code, doesn't seem to be anything wrong with it, but I can check the errors if I can see your gallery.
Logged
jvcam.co.uk

flex

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 29
Watermarking hack (w/ ImageMagick)
« Reply #17 on: November 14, 2003, 01:14:03 pm »

ok all fixed up for working in windows as well now. Imagemagick in windows didn't like using single quotes around the filenames, changed them to double quotes.

Thanks to terrorhawk for letting me test on his server & helping me fix it!

I updated the source on my previous post to reflect.
Logged
jvcam.co.uk

gdn

  • Coppermine newbie
  • Offline Offline
  • Posts: 8
Watermarking hack (w/ ImageMagick)
« Reply #18 on: November 20, 2003, 10:46:42 am »

OK, I installed the hack and here's what I got:

Code: [Select]
Fatal error: Call to undefined function: get_pic_url() in /home/sites/site72/web/coppermine/index.php on line 462

 :?
Logged
Loïc

gdn

  • Coppermine newbie
  • Offline Offline
  • Posts: 8
Watermarking hack (w/ ImageMagick)
« Reply #19 on: November 21, 2003, 05:21:27 pm »

Forget it... I used DJ Axion hack, and it runs OK.

The only problem I have is that I want to allow people to download the pics. And when you click right and click "save as", "logo.htm" is in the name field. I would like something like "file" or "image", just like in your hack. An idea about what I have to do?
Logged
Loïc
Pages: [1] 2 3 4 5 6   Go Up
 

Page created in 0.028 seconds with 20 queries.