Watermarking MOD with ImageMagick for cpg 1.4.x Watermarking MOD with ImageMagick for cpg 1.4.x
 

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

Main Menu

Watermarking MOD with ImageMagick for cpg 1.4.x

Started by emielk, January 23, 2006, 04:54:03 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

emielk

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)

$filepathname = $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
               $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:




<?
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


Zeitgeist

#1
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:

        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...
I love GauGau!

Skully1

#2
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.


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']);
        }

BeEbAcK

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 :<


Joachim Müller

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?

mukoh


Tranz


zenith


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.

zenith


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:

<?
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.



debragrant

Quote".realpath("./watermark.png")


is that where I place thecomplete path to the watermark? anywhere else?

Zarzal

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.

mattocean

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

Stramm

this mod requires ImageMagick as you can read in the topics subject

GigaPixel

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.

joel2280

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

joel2280

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??

Nibbler

Either get imagemagick installed or rewrite the mod for GD2.

joel2280

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

Nibbler

Post on the upload troubleshooting board after reading the upload troubleshooting guide.

PirateZipp

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)
.