forum.coppermine-gallery.net

No Support => Modifications/Add-Ons/Hacks => Mods: Watermarking & image manipulation => Topic started by: emielk on January 23, 2006, 04:54:03 pm

Title: Watermarking MOD with ImageMagick for cpg 1.4.x
Post by: emielk on January 23, 2006, 04:54:03 pm
Hi there,

I always used the watermarking hack from flex: http://forum.coppermine-gallery.net/index.php?topic=1467.0

Thank you flex for this hack!

This one did not work in coppermine version 1.4.3 anymore.

I looked through the code and I found the place where you should place the modifications. So here is the posting again with the modifications for 1.4.3

Step 1. includes/functions.inc.php


Find this line in the script:

(line 1985)

Code: [Select]
$filepathname = $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
               $filepathname = "wm.php?pid=".$pic_row["pid"]."&mode=".$mode;

       }else{
               // it's a thumb, don't bother wm'ing
               $filepathname = $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 mine (or actually my girlfriend her watermark) from here:
http://www.vankalken.net/gallery/watermark.png

Remember to edit it first ;)

And put it in your root coppermine directory.

Remember I'm not a PHP programmer, I can read the code, but not create new code   :P

Regards,

Emiel from the Netherlands

http://www.vankalken.net/gallery

Title: Re: Watermarking MOD with ImageMagick for cpg 1.4.3
Post by: Zeitgeist on February 22, 2006, 01:28:06 am
Good Job, I used this on 1.3 and this works just as great.

Another useful and simple modification would be to have different watermarks for the intermediate and full sized pictures.

To do this simply change the functions.inc.php code to as follows:
Code: [Select]
        if(($mode == "fullsize") && ($CONFIG['thumb_method']=='im')){

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

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

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

}else{

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

        }

Then copy wm.php to wm2.php and change the filename of the png in wm2.php. And that's about it for my elite coding skills...
Title: Re: Watermarking MOD with ImageMagick for cpg 1.4.3
Post by: Skully1 on February 23, 2006, 03:45:45 am
Hi all,
I found that while the MOD works awesome for images, it locks up video and audio from playing.

I've further modified the code.  It excludes non-images from being unnecessarily watermarked.

Code: [Select]

if(($mode == "fullsize") && ($CONFIG['thumb_method']=='im') && ($mime_content['content'] == 'image' )){

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

        }else if((($mode == "normal")) && ($CONFIG['thumb_method']=='im') && ($mime_content['content'] == 'image')){

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

}else{
               
                        // it's a thumb, don't bother wm'ing
        $filepathname = $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);
        }
Title: Re: Watermarking MOD with ImageMagick for cpg 1.4.3
Post by: BeEbAcK on May 08, 2006, 08:09:42 pm
well i tryed emielk step-by-step ... and watermark isnt showing... i even for test tryed to use his and notnig :<  where did i go wrong :<

Title: Re: Watermarking MOD with ImageMagick for cpg 1.4.3
Post by: Joachim Müller on May 09, 2006, 05:55:21 am
impossible to say without being able to look at your changes and not even a link to your site ::). Do you actually have ImageMagick? Did you try the (more popular) watermarking mod posted by Stramm (http://forum.coppermine-gallery.net/index.php?topic=29817.0)?
Title: Re: Watermarking MOD with ImageMagick for cpg 1.4.3
Post by: mukoh on May 30, 2006, 07:40:17 pm
Will this work with 1.4.6?
Title: Re: Watermarking MOD with ImageMagick for cpg 1.4.3
Post by: Tranz on May 31, 2006, 05:38:57 am
It's marked 1.4.x, x meaning any number.
Title: Re: Watermarking MOD with ImageMagick for cpg 1.4.x
Post by: zenith on June 20, 2006, 04:27:30 pm

wm.php sets the image's filename to "file.jpg".
Is there any way to change this so that the original file name comes up when a user tries to save the image?

regards,
zenith.
Title: Re: Watermarking MOD with ImageMagick for cpg 1.4.x
Post by: zenith on June 21, 2006, 08:55:30 pm

Worked it out.

had to move the header section further down to after where $row is set. Then replace "file.jpg" with the variable $row["filename"].

Code now looks like this:
Code: [Select]
<?
define('IN_COPPERMINE', true);
require('include/init.inc.php');


$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' => ''
);

header('Content-Type: image/jpeg');
header("Content-Disposition: inline; filename=".($row["filename"]).";");

$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;

?>

Hope it helps someone.

Zenith.


Title: Re: Watermarking MOD with ImageMagick for cpg 1.4.x
Post by: debragrant on July 16, 2006, 09:00:37 pm
Quote
".realpath("./watermark.png")


is that where I place thecomplete path to the watermark? anywhere else?
Title: Re: Watermarking MOD with ImageMagick for cpg 1.4.x
Post by: Zarzal on October 17, 2006, 11:35:12 pm
Anyone try this in 1.4.9? It seems to me that this is the only on-the-fly mod without touching the files. All other hacks modify the source.
Title: Re: Watermarking MOD with ImageMagick for cpg 1.4.x
Post by: mattocean on November 06, 2006, 09:16:18 am
Hi,

I am new here and would like to ask the experts: do I need ImageMagick for watermark the uploaded images? Is it possible to watermark the images something else?

Thanks ;)
Title: Re: Watermarking MOD with ImageMagick for cpg 1.4.x
Post by: Stramm on November 06, 2006, 09:21:04 am
this mod requires ImageMagick as you can read in the topics subject
Title: Re: Watermarking MOD with ImageMagick for cpg 1.4.x
Post by: GigaPixel on November 08, 2006, 03:44:37 pm
Thankyou very much emielk.

I couldn't get Flex's original MOD to work because I think includes/functions.inc.php is quite different in later versions. i.e. the line that needs to be ammended is not at the end of the script.

So I can confirm that your version of this Watermark MOD works perfectly with:

Coppermine version 1.4.10.
ImageMagick-6.2.5.4
php-5.1.4-1
mysql-5.0.18-2.1

on Fedora Core 5

Thanks very much, Ben.
 
Title: Re: Watermarking MOD with ImageMagick for cpg 1.4.x
Post by: joel2280 on February 27, 2007, 09:39:22 pm
I love this mod...its cool and simple I have A problem though.

It only works with image magic.....
is there a way to get it to work with GD version 1 or 2??

When I have Image magic turned on it wont let me upload so I have to use GD.....

Please help!!
Ive been up for 16 hours triing to get this up and running smoothly.:o :o

Thanks!!  ;D ;D
Title: Re: Watermarking MOD with ImageMagick for cpg 1.4.x
Post by: joel2280 on February 27, 2007, 10:02:33 pm
Im using coppermine 1.4.10 ..........and this is whats going on..... does anyone have a fix for it?

 I can only upload images with images with GD, and with image magic it wont let me upload.....
is there a way to get this mod to work with GD version 1 or 2??


or is there a way I can upload using image magic.
this is the only mod I'm running....I don't know whats wrong?

can anyone help??
Title: Re: Watermarking MOD with ImageMagick for cpg 1.4.x
Post by: Nibbler on February 27, 2007, 10:04:07 pm
Either get imagemagick installed or rewrite the mod for GD2.
Title: Re: Watermarking MOD with ImageMagick for cpg 1.4.x
Post by: joel2280 on February 27, 2007, 10:25:47 pm
I have image magic installed......when I have it turned on and I try to upload a file I get this message....
The previous file could not be placed. You have successfully placed all the files. (so it wont let me upload).

It did work for a while but then started doing that..... while it was working the watermark mod worked great.

So I turn on GD version 1 or 2 in config so I could upload again(now I can upload without any probs)...but now the watermark mod doesnt work.....arrrrrg pulling my hair out!!!

can anyone help???

Im running version 1.4.10
Title: Re: Watermarking MOD with ImageMagick for cpg 1.4.x
Post by: Nibbler on February 27, 2007, 10:26:47 pm
Post on the upload troubleshooting board after reading the upload troubleshooting guide.
Title: Re: Watermarking MOD with ImageMagick for cpg 1.4.x
Post by: PirateZipp on March 12, 2007, 10:34:26 am
Hey.. im thinking of whis program to edit the .png in??

if i try edit it in paint the text is only a black line...

Thx.

Sry for my bad english..
Sebastian
(denmark)
Title: Re: Watermarking MOD with ImageMagick for cpg 1.4.x
Post by: Joachim Müller on March 12, 2007, 12:52:12 pm
Any desktop app capable of handling PNGs is fine. This thread doesn't cover desktop app support. You could try Paint.NET (http://www.getpaint.net/) for a start. Please do not clutter this thread with desktop app related questions nor remarks.
Title: Re: Watermarking MOD with ImageMagick for cpg 1.4.x
Post by: PirateZipp on March 22, 2007, 08:27:44 pm
hmm... I love this mod.. but i found out that i got som problems with activ .gif images..

http://de2dumme.dk/galleri/displayimage.php?album=41&pos=0

how can i doo somthing about that???
Title: Re: Watermarking MOD with ImageMagick for cpg 1.4.x
Post by: Joachim Müller on March 23, 2007, 09:14:45 am
You're probably refering to animated GIFs - see my reply http://forum.coppermine-gallery.net/index.php?topic=42473.msg201605#msg201605
Not related to this mod.
Title: Re: Watermarking MOD with ImageMagick for cpg 1.4.x
Post by: PirateZipp on March 24, 2007, 02:36:22 am
yes and no... i got som problems with the animated gif in FF yes...

but the wathermark kills all my animated gif in both FF and IE if you see my link
http://de2dumme.dk/galleri/displayimage.php?pos=-80
you vill see that the aniation doo not work and the wathermark make so of the pic black...

is there any way to ake the script not wathermark the gif images???

but thx for the thumb info
Title: Re: Watermarking MOD with ImageMagick for cpg 1.4.x
Post by: mykee on November 21, 2007, 09:15:35 pm
I have a problem with this mod:
when I use original version functions.inc.php I have not problem when try save file. Filname is ok. But when I changed to moded functions.inc.php file, then when I try save file in IE7, then I get Untitled.bmp filename. Why?
Title: Re: Watermarking MOD with ImageMagick for cpg 1.4.x
Post by: Joachim Müller on November 22, 2007, 09:11:41 am
Stop spreading your issue over various threads! You already have asked this in a separate thread.