Watermark in Coppermine 1.2.2b (Need a little code help)

  Post new topicReply to topicPrintable Version
<< View previous topic View next topic >>
Share: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
#1   Watermark in Coppermine 1.2.2b (Need a little code help)
Dauthus
CZ Addict
 Codezwiz Site Donator
Dauthus has been a member for over 20 year's 20 Year Member
usa.gif illinois.gif
Age: 61
Gender: Male
Website:
Status: Offline
Joined: Mar 17, 2004
0.06 posts per day
Posts: 426
Points: 15,917
   
This code originally came from [ Register or login to view links on this board. ] They were discussing it on a post that is located here:
[ Register or login to view links on this board. ]

This code should allow a watermark on images in coppermine galleries using imagemagick. The watermarks are different if a user is registered or a guest.

The way this works is you have to create 2 transparent png files called watermark.png and watermark2.png. These have to be uploaded to your modules/coppermine directory. You then create two files one called wm.php with the following code:

<?
//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"];

$dbhost = "Put your database host IP here";
$dbuname = "DB user name";
$dbpass = "DB password";
$dbname = "nuke";
$prefix = "nuke";
$normal_pfx = "normal_";
$thumb_pfx = "thumb_";
$impath = "Dir ath to imagemagic";
$TABLE_PREFIX  = "cpg_";
$mainpath = "Dir path to the root of you web site";

$sql = "SELECT * FROM ".$TABLE_PREFIX."pictures WHERE pid=$pid";
$db = mysql_connect($dbhost, $dbuname, $dbpass);
mysql_select_db($dbname, $db);


$result = mysql_query($sql, $db);
$row = mysql_fetch_array($result);

$pic_prefix = array(
    'thumb' => $thumb_pfx,
    'normal' => $normal_pfx,
    'fullsize' => ''
);


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

passthru ($cmd, $output);

echo $output;
?>


The other wm2.php with the code:

<?
//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"];

$dbhost = "Put your database host IP here";
$dbuname = "DB user name";
$dbpass = "DB password";
$dbname = "nuke";
$prefix = "nuke";
$normal_pfx = "normal_";
$thumb_pfx = "thumb_";
$impath = "Dir ath to imagemagic";
$TABLE_PREFIX  = "cpg_";
$mainpath = "Dir path to the root of you web site";

$sql = "SELECT * FROM ".$TABLE_PREFIX."pictures WHERE pid=$pid";
$db = mysql_connect($dbhost, $dbuname, $dbpass);
mysql_select_db($dbname, $db);


$result = mysql_query($sql, $db);
$row = mysql_fetch_array($result);

$pic_prefix = array(
    'thumb' => $thumb_pfx,
    'normal' => $normal_pfx,
    'fullsize' => ''
);


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

passthru ($cmd, $output);

echo $output;
?>


Both of these files load into the modules/coppermine directory.

Then you need to modify the "\coppermine\include\functions.inc.php" with the following code:

Look for "function get_pic_url"

// Return the url for a picture, allows to have pictures spreaded over multiple servers
function get_pic_url(&$pic_row, $mode)
{
    global $CONFIG,$USER_DATA,$cat;
    static $pic_prefix = array();
    static $url_prefix = array();
    if (!count($pic_prefix)) {
        $pic_prefix = array('thumb' => $CONFIG['thumb_pfx'],
            'normal' => $CONFIG['normal_pfx'],
            'fullsize' => ''
            );
        $url_prefix = array(0 => $CONFIG['fullpath'],
            );
    }
    //return path2url($pic_row['filepath'] . $pic_prefix[$mode] . $pic_row['filename']);
    //Begin mod  mike
     //echo $cat;
     //echo $USER_DATA['group_id'];
    if((($mode == "normal") || ($mode == 'fullsize')) && ($CONFIG['thumb_method']=='im') && (($cat != '22') && ($cat != '23') && ($cat != '-56') && ($cat != '-57') && ($cat != '-58') && ($cat != '-59') && ($cat != '-60') && ($cat != '-61'))  ){

      If(($USER_DATA['group_id'] == 2) || ($USER_DATA['group_id'] == 1)){
        // return the url to the wm script
        return "modules/coppermine/wm.php?pid=".$pic_row["pid"]."&mode=".$mode;
      }else{
        return "modules/coppermine/wm2.php?pid=".$pic_row["pid"]."&mode=".$mode;
       }

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

   }
   //end mod
}


I have made what I am fairly sure are the correct changes in wm.php and wm2.php by the following:

$dbhost = "localhost";
$dbuname = "";
$dbpass = "";
$dbname = "night-blues_com_-_nuke";
$prefix = "nuke";
$normal_pfx = "normal_";
$thumb_pfx = "thumb_";
$impath = "/usr/bin/";
$TABLE_PREFIX  = "nuke_cpg_";
$mainpath = "/var/www/html/nuke";


Any help could be appreciated with this. It looks like the images aren't being called up correctly, because after loading this, the thumbnails work, but the normal images don't.



_________________
[ Register or login to view links on this board.]
Vivere disce, cogita mori
Back to top Reply with quote
Display posts from previous:      
Add To: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
<< View previous topic View next topic >>
Post new topicReply to topic

Jump to 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum