forum.coppermine-gallery.net

No Support => Modifications/Add-Ons/Hacks => Mods: Watermarking & image manipulation => Topic started by: TheGamer1701 on January 06, 2006, 03:35:02 pm

Title: Permanant watermark with undo possibility (GD2+IMagick) for 1.4.3
Post by: TheGamer1701 on January 06, 2006, 03:35:02 pm
Hello,

this is my first try for a modification, so bare with me if there are mistakes.
And I also hope that this is the right place to put it into.
This modification is based on the Mod by Stramm: http://forum.coppermine-gallery.net/index.php?topic=16286.0 (http://forum.coppermine-gallery.net/index.php?topic=16286.0)

It's still under develpoment and this thread is supposed to be a help to complete it.
I did not create a new mod, it's just a conversion of the old 132 mod for the new coppermine version (1.4.3)



The mod doesn't produce any kind of error, uploading works just fine, but the images doen't get watermarked. I did not have enough time to look into the code today, I'll hopefully have enough time by tomorrow.
I'll post the mod instructions with the next post

what's working:
- uploading of files works
- all 3 files are created (full sized file, resized file, thumbnail)

what's not working:
- watermarking at all (:-( )
Title: Re: Permanant watermark with undo possibility (GD2+IMagick) for 1.4.3
Post by: TheGamer1701 on January 06, 2006, 03:48:22 pm
Okay,
so let's begin.
First we need some sql statements.
I would suggest to execute them one by one, this way it's easiert to track down errors.
I had the problem that some etrys already existet because I installed CPGMark and when deinstalling CPGMark it seemed that it did not delete those entries.

Code: [Select]
insert into cpg_config (name, value) values ('enable_watermark', '1');
insert into cpg_config (name, value) values ('where_put_watermark', 'bottomright');
insert into cpg_config (name, value) values ('watermark_file', '/your/full/path/to/logo.png');
insert into cpg_config (name, value) values ('which_files_to_watermark', 'both');
insert into cpg_config (name, value) values ('orig_pfx', 'orig_');
insert into cpg_config (name, value) values ('watermark_transparency', '0');
insert into cpg_config (name, value) values ('watermark_transparency_featherx', '0');
insert into cpg_config (name, value) values ('watermark_transparency_feathery', '0');



Okay,
now let's begin.
What files need to be edited?
language/german.php (or your language file, e.g. english.php)
admin.php
util.php
delete.php
editpics.php
searchnew.php
include/picmgmt.inc.php (we make a complete new file)



so, let's start with your language file.
open german.php
in $lang_admin_data
find
Code: [Select]
// ------------------------------------------------------------------------- //
// File db_ecard.php
// ------------------------------------------------------------------------- //
and a few lines before find
Code: [Select]
);before add
Code: [Select]
  // Watermarking mod
  'Wasserzeichen',
  array('Wasserzeichen aktivieren', 'enable_watermark', 1),
  array('Wo soll das Wasserzeichen eingefügt werden', 'where_put_watermark', 11),
  array('Welche Dateien sollen mit einem Wasserzeichen versehen werden', 'which_files_to_watermark', 12),
  array('Welche Datei soll für das Wasserzeichen verwendet werden', 'watermark_file', 0),
  array('Transparenz 0-100 für gesamtes Bild', 'watermark_transparency', 0),
  array('Koordinate der transparenten Farbe X (Nur GD2)', 'watermark_transparency_featherx', 0),
  array('Koordinate der transparenten Farbe y (Nur GD2)', 'watermark_transparency_feathery', 0),
  // End Mod


in $lang_util_php
find
Code: [Select]
'delete_orphans' =>after add
Code: [Select]
  // Watermarking mod
  'update_full' => 'Beide Bilder (falls eine Kopie des Originals vorhanden ist)',
  'delete_back' => 'Backup des Originals löschen (Wenn du dies tust kannst du das Wasserzeichen nicht mehr entfernen/ändern)',
  'delete_back_explanation' => 'Diese Option löscht alle Original Bilder. Wenn du diese Option ausführst kannst du hinterher die Wasserzeichen bei bestehenden Dateien weder ändern noch entfernen.',
  // End mod

in $lang_delete_php
find
Code: [Select]
// ------------------------------------------------------------------------- //
// File displayecard.php
//


few lines before find
Code: [Select]
);
before add
Code: [Select]
  // Watermarking mod
  'orig_pic' => 'Original Bild',

go to end of file
find
Code: [Select]
?>before add
Code: [Select]
// Watermarking mod
$lang_config_php = array(
  'wm_bottomright' => 'Unten Rechts',
  'wm_bottomleft' => 'Unten Links',
  'wm_topleft' => 'Oben Links',
  'wm_topright' => 'Oben Rechts',
  'wm_center' => 'Mitte',
  'wm_both' => 'Beide',
  'wm_original' => 'Original',
  'wm_resized' => 'Zwischengröße');


open admin.php
find
Code: [Select]
function create_form(&$data)before add
Code: [Select]
// Watermarking mod start
function form_watermark($text, $name)
{
    global $CONFIG, $lang_config_php;

    $value = $CONFIG[$name];
    $southeast_selected = ($value == 'southeast') ? 'selected' : '';
    $southwest_selected = ($value == 'southwest') ? 'selected' : '';
    $northwest_selected = ($value == 'northwest') ? 'selected' : '';
    $northeast_selected = ($value == 'northeast') ? 'selected' : '';
    $center_selected = ($value == 'center') ? 'selected' : '';

    echo <<<EOT
        <tr>
            <td class="tableb">
                        $text
        </td>
        <td class="tableb" valign="top">
                        <select name="$name" class="listbox">
                                <option value="southeast" $southeast_selected>{$lang_config_php['wm_bottomright']}</option>
                                <option value="southwest" $southwest_selected>{$lang_config_php['wm_bottomleft']}</option>
                                <option value="northwest" $northwest_selected>{$lang_config_php['wm_topleft']}</option>
                                <option value="northeast" $northeast_selected>{$lang_config_php['wm_topright']}</option>
                                <option value="center" $center_selected>{$lang_config_php['wm_center']}</option>
                        </select>
                </td>
        </tr>

EOT;
}
// Added for allowing user to select which files to watermark...
function form_watermark2($text, $name)
{
    global $CONFIG, $lang_config_php;

    $value = $CONFIG[$name];
    $both_selected = ($value == 'both') ? 'selected' : '';
    $original_selected = ($value == 'original') ? 'selected' : '';
    $resized_selected = ($value == 'resized') ? 'selected' : '';

    echo <<<EOT
        <tr>
            <td class="tableb">
                        $text
        </td>
        <td class="tableb" valign="top">
                        <select name="$name" class="listbox">
                                <option value="both" $both_selected>{$lang_config_php['wm_both']}</option>
                                <option value="original" $original_selected>{$lang_config_php['wm_original']}</option>
                                <option value="resized" $resized_selected>{$lang_config_php['wm_resized']}</option>
                        </select>
                </td>
        </tr>

EOT;
}
// Watermarking mod end


find
Code: [Select]
form_number_dropdown($element[0], $element[1]few lines below find
Code: [Select]
default:
die('Invalid action');
before add
Code: [Select]
// Watermarking Mod
//Watermark place
   case 18 :
       form_watermark($element[0], $element[1]);
       break;
//Which filest to watermark
    case 19 :
        form_watermark2($element[0], $element[1]);
        break;
    case 20 :
// do nothing
        break;
// End Mod
Title: Re: Permanant watermark with undo possibility (GD2+IMagick) for 1.4.3
Post by: TheGamer1701 on January 06, 2006, 03:56:28 pm
open util.php
find
Code: [Select]
<input type="radio" name="updatetype" id="updatetype3" value="2" checked="checked" class="nobg" /><label for="updatetype3" class="clickable_option">'.$lang_util_php['update_both'].'</label><br />'.$lang_util_php['update_number'].'after add
Code: [Select]
<input type="radio" name="updatetype" value="3" id="full" class="nobg" /><label for="full" accesskey="a" class="labelradio">' . $lang_util_php['update_full'] . '</label><br />

find
Code: [Select]
'del_norm' => array('del_norm', $lang_util_php['delete_intermediate'], $lang_util_php['delete_intermediate_explanation']),after add
Code: [Select]
// Watermarking Mod
'delback' => array('delback', $lang_util_php['delete_back'], $lang_util_php['delete_back_explanation']),
// End Mod


find
Code: [Select]
function del_orphans()before add
Code: [Select]
// Watermarking Mod
function del_back()
{
    global $picturetbl, $CONFIG, $lang_util_php;
    $albumid = $_POST['albumid'];

    $query = "SELECT * FROM $picturetbl WHERE aid = '$albumid'";
    $result = MYSQL_QUERY($query);
    $num = mysql_numrows($result);

    $i = 0;
    while ($i < $num) {
        $pid = mysql_result($result, $i, "pid");
        $back = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") . $CONFIG['orig_pfx'] . mysql_result($result, $i, "filename");

        if (file_exists($back)) {
if(unlink($back)){
                printf($lang_util_php['main_success'], $back);
                print '!<br>';
}
            } else {
                printf($lang_util_php['error_rename'], $back);
            }
        ++$i;
    }
}


find
Code: [Select]
function update_thumbs()and replace the whole function with:
Code: [Select]
// Watermarking mod
function update_thumbs()
{
set_time_limit(3600);
    global $picturetbl, $CONFIG, $lang_util_php;
    $phpself = $_SERVER['PHP_SELF'];
    $albumid = $_POST['albumid'];
    $updatetype = $_POST['updatetype'];
    $numpics = $_POST['numpics'];
    $startpic = 0;
    $startpic = $_POST['startpic'];

    $query = "SELECT * FROM $picturetbl WHERE aid = '$albumid'";
    $result = MYSQL_QUERY($query);
    $totalpics = mysql_numrows($result);
$watermark="";

    if ($startpic == 0) {
        // 0 - numpics
        $num = $totalpics;
        // Over picture limit
        if ($totalpics > $numpics) $num = $startpic + $numpics;
    } else {
        // startpic - numpics
        $num = $startpic + $numpics;
        if ($num > $totalpics) $num = $totalpics;
    }

    $i = $startpic;
    while ($i < $num) {
$imagepath=mysql_result($result, $i, "filepath");
$imagefilename=mysql_result($result, $i, "filename");
$orig=$CONFIG['fullpath'] . $imagepath . $CONFIG['orig_pfx'] . $imagefilename;
        $image = $CONFIG['fullpath'] . $imagepath . $imagefilename;
$work_image = $image;
$orig_true='false';
if (file_exists($orig)) {
$work_image=$orig;
$orig_true='true';
}
else
$work_image=$image;
        if ($updatetype == 0 || $updatetype == 2) {
            $thumb = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") . $CONFIG['thumb_pfx'] . mysql_result($result, $i, "filename");

            if (resize_image($work_image, $thumb, $CONFIG['thumb_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use'], "false")) {
                print $thumb .' '. $lang_util_php['updated_succesfully'] . '!<br />';
                my_flush();
            } else {
                print $lang_util_php['error_create'] . ':$thumb<br />';
                my_flush();
            }
        }

        if ($updatetype == 1 || $updatetype == 2 || $updatetype == 3)
{
            $normal = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") . $CONFIG['normal_pfx'] . mysql_result($result, $i, "filename");
            if ($CONFIG['enable_watermark'] == '1' && $CONFIG['which_files_to_watermark'] == 'both' || $CONFIG['which_files_to_watermark'] == 'resized')
{$watermark="true";}
else
{$watermark="false";}
            $imagesize = getimagesize($work_image);
            if (max($imagesize[0], $imagesize[1]) > $CONFIG['picture_width'] && $CONFIG['make_intermediate'])
{
                if (resize_image($work_image, $normal, $CONFIG['picture_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use'], $watermark))
{
                    print $normal . $lang_util_php['updated_succesfully'] . '!<br />';
                    my_flush();
}
                else
{
                    print $lang_util_php['error_create'] . ':$normal<br />';
                    my_flush();
}
}
}
       
        if ($updatetype == 3)
{
if ($orig_true == 'false')
{
if (copy($image, $orig))
{        
if ($CONFIG['enable_watermark'] == '1' && $CONFIG['which_files_to_watermark'] == 'both' || $CONFIG['which_files_to_watermark'] == 'original')
{
if (resize_image($orig, $image, $imagesize[0], $CONFIG['thumb_method'], $CONFIG['thumb_use'], "true"))
{
             print $image . $lang_util_php['updated_succesfully'] . '!<br />';
             my_flush();
}
}
}
}
else
{
if ($CONFIG['enable_watermark'] == '1' && $CONFIG['which_files_to_watermark'] == 'both' || $CONFIG['which_files_to_watermark'] == 'original')
{
        $imagesize = getimagesize($orig);
if (resize_image($orig, $image, $imagesize[0], $CONFIG['thumb_method'], $CONFIG['thumb_use'], "true"))
{
             print $image . $lang_util_php['updated_succesfully'] . '!<br />';
             my_flush();
}
}
else
{
if (copy($orig, $image))
{
                    print $orig . $lang_util_php['updated_succesfully'] . '!<br />';
                    my_flush();
}
}
}
}

        ++$i;
    }
    $startpic = $i;

    if ($startpic < $totalpics) {

        ?>
            <form action=<?php echo $phpself;
        
?>
method="post">
                    <input type="hidden" name="action" value="continuethumbs" />
                    <input type="hidden" name="numpics" value="<?php echo $numpics?>" />
                    <input type="hidden" name="startpic" value="<?php echo $startpic?>" />
                    <input type="hidden" name="updatetype" value="<?php echo $updatetype?>" />
            <input type="hidden" name="albumid" value="<?php echo $albumid?>" />
            <input type="submit" value="<?php print $lang_util_php['continue'];
        
?>
" class="submit" /></form>
                    <?php
    
}
}
// End Watermarking mod


open delete.php
find
Code: [Select]
case 'picture':few lines before find
Code: [Select]
echo "<tr><td colspan=\"6\" class=\"tablef\" align=\"center\">\n";replace with
Code: [Select]
echo "<tr><td colspan=\"7\" class=\"tablef\" align=\"center\">\n";
find
Code: [Select]
<td class="tableh2" align="center"><b>{$lang_delete_php['ns_pic']}</b></td>after add
Code: [Select]
<td class="tableh2" align="center"><b>{$lang_delete_php['orig_pic']}</b></td>
find
Code: [Select]
<tr><td><b>T</b></td><td>:</td><td><?php echo $lang_delete_php['thumb_pic'?></td></tr>before add
Code: [Select]
<tr><td><b>O</b></td><td>:</td><td><?php echo $lang_delete_php['orig_pic'?></td></tr>
find
Code: [Select]
function delete_picture($pid)in function find
Code: [Select]
$files = array($dir . $file, $dir . $CONFIG['normal_pfx'] . $file, $dir . $CONFIG['thumb_pfx'] . $file);replace with
Code: [Select]
$files = array($dir . $file, $dir . $CONFIG['normal_pfx'] . $file, $dir . $CONFIG['thumb_pfx'] . $file, $dir . $CONFIG['orig_pfx'] . $file);
Title: Re: Permanant watermark with undo possibility (GD2+IMagick) for 1.4.3
Post by: TheGamer1701 on January 06, 2006, 03:59:17 pm
okay, you're almost done.

open editpics.php
find
Code: [Select]
$files=array($dir.$file, $dir.$CONFIG['normal_pfx'].$file, $dir.$CONFIG['thumb_pfx'].$file);replace with
Code: [Select]
$files=array($dir.$file, $dir.$CONFIG['normal_pfx'].$file, $dir.$CONFIG['thumb_pfx'].$file, $dir.$CONFIG['orig_pfx'].$file);

open searchnew.php
find
Code: [Select]
if (strncmp($file, $CONFIG['thumb_pfx'], strlen($CONFIG['thumb_pfx'])) != 0 && strncmp($file, $CONFIG['normal_pfx'], strlen($CONFIG['normal_pfx'])) != 0 && $file != 'index.html')replace with
Code: [Select]
if (strncmp($file, $CONFIG['orig_pfx'], strlen($CONFIG['orig_pfx'])) != 0 && strncmp($file, $CONFIG['thumb_pfx'], strlen($CONFIG['thumb_pfx'])) != 0 && strncmp($file, $CONFIG['normal_pfx'], strlen($CONFIG['normal_pfx'])) != 0 && $file != 'index.html')

remove or rename file
Code: [Select]
include/picmgmt.inc.php
make new file include/picmgmt.inc.php
add
Code: [Select]
<?php
// ------------------------------------------------------------------------- //
// Coppermine Photo Gallery 1.3.2                                            //
// ------------------------------------------------------------------------- //
// Copyright (C) 2002-2004 Gregory DEMAR                                     //
// http://www.chezgreg.net/coppermine/                                       //
// ------------------------------------------------------------------------- //
// Updated by the Coppermine Dev Team                                        //
// (http://coppermine.sf.net/team/)                                          //
// see /docs/credits.html for details                                        //
// ------------------------------------------------------------------------- //
// This program is free software; you can redistribute it and/or modify      //
// it under the terms of the GNU General Public License as published by      //
// the Free Software Foundation; either version 2 of the License, or         //
// (at your option) any later version.                                       //
// ------------------------------------------------------------------------- //
// CVS version: $Id: picmgmt.inc.php,v 1.8 2004/07/27 13:58:04 oddeveloper Exp $
// ------------------------------------------------------------------------- //

// Add a picture to an album
function add_picture($aid$filepath$filename$title ''$caption ''$keywords ''$user1 ''$user2 ''$user3 ''$user4 ''$category 0$raw_ip ''$hdr_ip '',$iwidth=0,$iheight=0)
{
    global 
$CONFIG$ERROR$USER_DATA$PIC_NEED_APPROVAL;
    global 
$lang_errors;

    
$image $CONFIG['fullpath'] . $filepath $filename;
    
$normal $CONFIG['fullpath'] . $filepath $CONFIG['normal_pfx'] . $filename;
    
$thumb $CONFIG['fullpath'] . $filepath $CONFIG['thumb_pfx'] . $filename;
    
$orig $CONFIG['fullpath'] . $filepath $CONFIG['orig_pfx'] . $filename;
$work_image $image;
    if (!
is_known_filetype($image)) {
        return 
false;
    } elseif (
is_image($filename)) {
if (!file_exists($orig) && $CONFIG['enable_watermark'] == '1' && ($CONFIG['which_files_to_watermark'] == 'both' || $CONFIG['which_files_to_watermark'] == 'original'))  {
// if copy of full_sized doesn't exist and if watermark enabled and if fullsized pic watermark=true -> then we need a backup
if (!copy($image$orig))
                return 
false;
else
$work_image $orig;
}
        if (!
file_exists($thumb)) {
            if (!
resize_image($work_image$thumb$CONFIG['thumb_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use'], "false"))
                return 
false;
        }
        
$imagesize getimagesize($work_image);
        if (
max($imagesize[0], $imagesize[1]) > $CONFIG['picture_width'] && $CONFIG['make_intermediate'] && !file_exists($normal)) {
            if (
$CONFIG['enable_watermark'] == '1' && $CONFIG['which_files_to_watermark'] == 'both' || $CONFIG['which_files_to_watermark'] == 'resized'){
if (!resize_image($work_image$normal$CONFIG['picture_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use'], "true"))
                
return false;
}
else {
if (!resize_image($work_image$normal$CONFIG['picture_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use'], "false"))
            return 
false;
}
}
/*else {
if (!resize_image($work_image, $normal, $CONFIG['picture_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use'], "false"))
                return false;

}*/
        
if ($CONFIG['enable_watermark'] == '1' && $CONFIG['which_files_to_watermark'] == 'both' || $CONFIG['which_files_to_watermark'] == 'original'){
if (!resize_image($work_image$image$imagesize[0], $CONFIG['thumb_method'], 'orig''true'))
                
return false;
}
    } else {
        
$imagesize[0] = $iwidth;
        
$imagesize[1] = $iheight;
    }


    
$image_filesize filesize($image);
    
$total_filesize is_image($filename) ? ($image_filesize + (file_exists($normal) ? filesize($normal) : 0) + filesize($thumb)) : ($image_filesize);


    
// Test if disk quota exceeded
    
if (!GALLERY_ADMIN_MODE && $USER_DATA['group_quota']) {
        
$result cpg_db_query("SELECT sum(total_filesize) FROM {$CONFIG['TABLE_PICTURES']}{$CONFIG['TABLE_ALBUMS']} WHERE  {$CONFIG['TABLE_PICTURES']}.aid = {$CONFIG['TABLE_ALBUMS']}.aid AND category = '" . (FIRST_USER_CAT USER_ID) . "'");
        
$record mysql_fetch_array($result);
        
$total_space_used $record[0];
        
mysql_free_result($result);

        if (((
$total_space_used $total_filesize)>>10) > $USER_DATA['group_quota'] ) {
            @
unlink($image);
            if (
is_image($image)) {
                @
unlink($normal);
                @
unlink($thumb);
            }
            
$msg strtr($lang_errors['quota_exceeded'], array('[quota]' => ($USER_DATA['group_quota']),
                
'[space]' => ($total_space_used >> 10)));
            
cpg_die(ERROR$msg__FILE____LINE__);
        }
    }
    
// Test if picture requires approval
    
if (GALLERY_ADMIN_MODE) {
        
$approved 'YES';
    } elseif (!
$USER_DATA['priv_upl_need_approval'] && $category == FIRST_USER_CAT USER_ID) {
        
$approved 'YES';
    } elseif (!
$USER_DATA['pub_upl_need_approval']) {
        
$approved 'YES';
    } else {
        
$approved 'NO';
    }
    
$PIC_NEED_APPROVAL = ($approved == 'NO');
    
// User ID is now recorded when in admin mode (casper)
    
$user_id USER_ID;
    
$usernameUSER_NAME;
    
$query "INSERT INTO {$CONFIG['TABLE_PICTURES']} (pid, aid, filepath, filename, filesize, total_filesize, pwidth, pheight, ctime, owner_id, owner_name, title, caption, keywords, approved, user1, user2, user3, user4, pic_raw_ip, pic_hdr_ip) VALUES ('', '$aid', '" addslashes($filepath) . "', '" addslashes($filename) . "', '$image_filesize', '$total_filesize', '{$imagesize[0]}', '{$imagesize[1]}', '" time() . "', '$user_id', '$username','$title', '$caption', '$keywords', '$approved', '$user1', '$user2', '$user3', '$user4', '$raw_ip', '$hdr_ip')";
    
$result cpg_db_query($query);

    return 
$result;
}

define("GIS_GIF"1);
define("GIS_JPG"2);
define("GIS_PNG"3);

// Add 'edit' directory if it doesn't exist
// Set access to read+write only
if (!is_dir($CONFIG['fullpath'].'edit')) {
    
$cpg_umask umask(0);
    @
mkdir($CONFIG['fullpath'].'edit',0666);
    
umask($cpg_umask);
    unset(
$cpg_umask);
}

/**
* resize_image()
*
* Create a file containing a resized image
*
* @param  $src_file the source file
* @param  $dest_file the destination file
* @param  $new_size the size of the square within which the new image must fit
* @param  $method the method used for image resizing
* @return 'true' in case of success
*/
function resize_image($src_file$dest_file$new_size$method$thumb_use$watermark="false")
{
    global 
$CONFIG$ERROR;
    global 
$lang_errors;

    
$imginfo getimagesize($src_file);
    if (
$imginfo == null)
        return 
false;
        
// GD can only handle JPG & PNG images
    
if ($imginfo[2] != GIS_JPG && $imginfo[2] != GIS_PNG && ($method == 'gd1' || $method == 'gd2')) {
        
$ERROR $lang_errors['gd_file_type_err'];
        return 
false;
    }
    
// height/width
    
$srcWidth $imginfo[0];
    
$srcHeight $imginfo[1];
    if (
$thumb_use == 'ht') {
        
$ratio $srcHeight $new_size;
    } elseif (
$thumb_use == 'wd') {
        
$ratio $srcWidth $new_size;
    } else {
        
$ratio max($srcWidth$srcHeight) / $new_size;
    }
    
$ratio max($ratio1.0);
if ($thumb_use == 'orig'$ratio=1.0;
    
$destWidth = (int)($srcWidth $ratio);
    
$destHeight = (int)($srcHeight $ratio);
    
// Method for thumbnails creation
    
switch ($method) {
        case 
"im" :
            if (
preg_match("#[A-Z]:|\\\\#Ai"__FILE__)) {
                
// get the basedir, remove '/include'
                
$cur_dir substr(dirname(__FILE__), 0, -8);
                
$src_file '"' $cur_dir '\\' strtr($src_file'/''\\') . '"';
                
$im_dest_file str_replace('%''%%', ('"' $cur_dir '\\' strtr($dest_file'/''\\') . '"'));
            } else {
                
$src_file escapeshellarg($src_file);
                
$im_dest_file str_replace('%''%%'escapeshellarg($dest_file));
            }

            
$output = array();
$anno_txt="";
$annotate="";

            
/*
             * Hack for working with ImageMagick on WIndows even if IM is installed in C:\Program Files.
             * By Aditya Mooley <aditya@sanisoft.com>
             */

                
$cmd "{$CONFIG['impath']}convert -quality {$CONFIG['jpeg_qual']} {$CONFIG['im_options']} -geometry {$destWidth}x{$destHeight} $annotate $src_file $im_dest_file";
exec ($cmd$output$retval);
if ($watermark == "true"){
$cmd "{$CONFIG['impath']}composite -dissolve {$CONFIG['watermark_transparency']} -gravity {$CONFIG['where_put_watermark']} {$CONFIG['watermark_file']} $im_dest_file $im_dest_file";
exec ($cmd$output$retval);
            
}

            if (
$retval) {
                
$ERROR "Error executing ImageMagick - Return value: $retval";
                if (
$CONFIG['debug_mode']) {
                    
// Re-execute the command with the backtit operator in order to get all outputs
                    // will not work is safe mode is enabled
                    
$output = `$cmd 2>&1`;
                    
$ERROR .= "<br /><br /><div align=\"left\">Cmd line : <br /><font size=\"2\">" nl2br(htmlspecialchars($cmd)) . "</font></div>";
                    
$ERROR .= "<br /><br /><div align=\"left\">The convert program said:<br /><font size=\"2\">";
                    
$ERROR .= nl2br(htmlspecialchars($output));
                    
$ERROR .= "</font></div>";
                }
                @
unlink($dest_file);
                return 
false;
            }
            break;

        case 
"gd1" :
            if (!
function_exists('imagecreatefromjpeg')) {
                
cpg_die(CRITICAL_ERROR'PHP running on your server does not support the GD image library, check with your webhost if ImageMagick is installed'__FILE____LINE__);
            }
            if (
$imginfo[2] == GIS_JPG)
                
$src_img imagecreatefromjpeg($src_file);
            else
                
$src_img imagecreatefrompng($src_file);
            if (!
$src_img) {
                
$ERROR $lang_errors['invalid_image'];
                return 
false;
            }
            
$dst_img imagecreate($destWidth$destHeight);
            
imagecopyresized($dst_img$src_img0000$destWidth, (int)$destHeight$srcWidth$srcHeight);
            
imagejpeg($dst_img$dest_file$CONFIG['jpeg_qual']);
            
imagedestroy($src_img);
            
imagedestroy($dst_img);
            break;

        case 
"gd2" :
            if (!
function_exists('imagecreatefromjpeg')) {
                
cpg_die(CRITICAL_ERROR'PHP running on your server does not support the GD image library, check with your webhost if ImageMagick is installed'__FILE____LINE__);
            }
            if (!
function_exists('imagecreatetruecolor')) {
                
cpg_die(CRITICAL_ERROR'PHP running on your server does not support GD version 2.x, please switch to GD version 1.x on the config page'__FILE____LINE__);
            }
            if (
$imginfo[2] == GIS_JPG)
                
$src_img imagecreatefromjpeg($src_file);
            else
                
$src_img imagecreatefrompng($src_file);
            if (!
$src_img) {
                
$ERROR $lang_errors['invalid_image'];
                return 
false;
            }
            
$dst_img imagecreatetruecolor($destWidth$destHeight);
            
imagecopyresampled($dst_img$src_img0000$destWidth, (int)$destHeight$srcWidth$srcHeight);
            
if ($watermark == "true"){
$logoImage ImageCreateFromPNG($CONFIG['watermark_file']); 
    $logoW ImageSX($logoImage); 
    $logoH ImageSY($logoImage); 
    //where is the watermark displayed... 
    $pos $CONFIG['where_put_watermark']; 
if ($pos == "northwest") { 
$src_x 5;  
$src_y 5
} else if ($pos == "northeast") { 
$src_x $destWidth - ($logoW 5); 
$src_y 5
} else if ($pos == "southwest") { 
$src_x 5
$src_y $destHeight - ($logoH 5); 
} else if ($pos == "southeast") { 
$src_x $destWidth - ($logoW 5); 
$src_y $destHeight - ($logoH 5); 
} else if ($pos == "center") { 
$src_x = ($destWidth/2) - ($logoW/2); 
$src_y = ($destHeight/2) - ($logoH/2); 


// no, we don't support that in the script, overkill... just make a transparentbkg png and don't be so lazy
//imagecolortransparent($logoImage, imagecolorat($logoImage, $CONFIG['watermark_transparency_featherx'], $CONFIG['watermark_transparency_feathery']));
imagealphablending($dst_imgTRUE);
imagecolortransparent($logoImageimagecolorat($logoImage$CONFIG['watermark_transparency_featherx'], $CONFIG['watermark_transparency_feathery']));
ImageCopyMerge($dst_img,$logoImage,$src_x,$src_y,0,0,$logoW,$logoH,$CONFIG['watermark_transparency']); //$dst_x,$dst_y,0,0,$logoW,$logoH); 
}
imagejpeg($dst_img$dest_file$CONFIG['jpeg_qual']);
            
imagedestroy($src_img);
            
imagedestroy($dst_img);
            break;
    }
    
// Set mode of uploaded picture
    
chmod($dest_fileoctdec($CONFIG['default_file_mode']));
    
// We check that the image is valid
    
$imginfo getimagesize($dest_file);
    if (
$imginfo == null) {
        
$ERROR $lang_errors['resize_failed'];
        @
unlink($dest_file);
        return 
false;
    } else {
        return 
true;
    }
}
?>
Title: Re: Permanant watermark with undo possibility (GD2+IMagick) for 1.4.3
Post by: bloodynipples on January 17, 2006, 03:58:57 am
Has anyone installed this mod?  How well does it work?
Title: Re: Permanant watermark with undo possibility (GD2+IMagick) for 1.4.3
Post by: Veseliq on January 19, 2006, 06:22:49 pm
The other plugin didnt work for me - I'll try it within 2-3 hours and post the results  ;)
Title: Re: Permanant watermark with undo possibility (GD2+IMagick) for 1.4.3
Post by: Joachim Müller on January 21, 2006, 07:21:32 am
Just to clarify: it's not a plugin, it's a mod. A plugin uses the plugin API that comes with cpg1.4.x - this mod doesn't.
Title: Re: Permanant watermark with undo possibility (GD2+IMagick) for 1.4.3
Post by: mrandall131 on January 23, 2006, 02:28:20 am
I'm very interested in this mod.  Did you ever get it installed?  Does this work without errors?

Thanks in advance.
Title: Re: Permanant watermark with undo possibility (GD2+IMagick) for 1.4.3
Post by: ausfuzzy on February 01, 2006, 06:10:07 am
hi
I'am new to this forum
I have tried this mod and i get no errors, but it doesnt put any watermarks on any images, so i think its not quite all there yet.
Title: Re: Permanant watermark with undo possibility (GD2+IMagick) for 1.4.3
Post by: bloodynipples on February 01, 2006, 06:02:55 pm
I also spent a good amount of time working on this last night and could not get it to work.  As you said, there are no errors, but it just doesn't watermark images.  I also noticed the admin pannel controls do not work as they should.  The options for "location of watermark" and "what images to watermark"  do not display as pull-down menus as expected, they display as the defaults - yes/no radio buttons.

I believe it is not completely compatable with 1.4.x and I am unsure if it will get there from here.  TheGamer1701 and others are currently working on a watermarking plugin.  Yes, a plugin not a mod. 

http://cpg-contrib.org/thumbnails.php?album=10
Title: Re: Permanant watermark with undo possibility (GD2+IMagick) for 1.4.3
Post by: cheenamalai on February 27, 2006, 04:29:07 am
I need to watermark my images upon uploading can this accomplish it?
Title: Re: Permanant watermark with undo possibility (GD2+IMagick) for 1.4.3
Post by: Stramm on February 27, 2006, 08:32:19 am
I haven't checked this version of the watermark mod so I can't say where it's problems are. Still my orig version works and is ported to 1.4x for quite some time (I just haven't it published as stand alone). You'll have to install my modpack. The difference between my watermark and the plugins (at least I think so) is that plugins watermark on the fly. Means they put heat on the server each time a pic gets displayed. So if you have some visits a day it's not recommended to use that but a permanent watermark as the one here. The advantage of that watermark solution is that it's saving a backup file. So you can undo the watermark if you once don't like it anymore.
I didn't open a standalone 1.4x watermark therad caujse I've written a good bunch of mods. And maintaining all the threads with a compatibility version to all the other mods is plain to much work for me.
So I still recommend the modpack. It has a lot of good functionallity. If you haven't seen the 'better thumbs' (thumb sharpening and cropping)... that's really worth a try. The minithumbs are cool too... and if you use category thumbs, then the mini thumbs may be from interest as well. They don't html reduce the cat preview pic but generate new thumbs that have exact the size you want to have for your category lead images. No fuzzy pics anymore but crystal clear images

Enough talkin.. if there's really (I mean really) need for the standalone version I might open a thread for it but I think I'm not able to pet the thread or give much support
Title: Re: Permanant watermark with undo possibility (GD2+IMagick) for 1.4.3
Post by: cheenamalai on February 27, 2006, 10:19:14 pm
So your saying that if i install your modpack it will give me capability to watermark my images automatically upon uploading while giving me the benefits of more clearer thumbnails?  ??? I am using 1.4x and i need to know what can i do to watermark my images upon just an upload so i dont have to go to photoshop to water mark images one by one.  :D

If you could provide me links to water mark mod and your thumbnail mod. I would appreciate it. Also i am looking for BBCODES for either [IMG] tags or the image link it self.

My gallery is located here: http://www.pakistaniforcesforum.com/gallery

Thank you very much.
Title: Re: Permanant watermark with undo possibility (GD2+IMagick) for 1.4.3
Post by: cheenamalai on March 02, 2006, 07:43:01 am
Stramm i think your busy or you haven't read my post.

So is there anybody else who can support me over the post i made above?

Thanks.
Title: Re: Permanant watermark with undo possibility (GD2+IMagick) for 1.4.3
Post by: Stramm on March 03, 2006, 09:06:22 am
yes, that's what I've said http://forum.coppermine-gallery.net/index.php?topic=28367.0
Title: Re: Permanant watermark with undo possibility (GD2+IMagick) for 1.4.3
Post by: cheenamalai on March 04, 2006, 06:31:47 am
Hey Stramm buddy i have sent you a PM i hope you will read it soon.

http://www.pakistaniforcesforum.com/gallery

Thanks.
Title: Re: Permanant watermark with undo possibility (GD2+IMagick) for 1.4.3
Post by: Stramm on March 04, 2006, 10:31:25 am
best is not to send me unrequested PMs. That's something you agreed on when you signed up here. And you should ask your questions in the related thread instead here...

short answer... I'm quoting the 2nd line in the first post of the modpack thread
Code: [Select]
For now I've added bridge files for PhpBB 2.0.18, 19 and SMF 1.0x
Title: Re: Permanant watermark with undo possibility (GD2+IMagick) for 1.4.3
Post by: cheenamalai on March 06, 2006, 02:29:33 am
So i can't bridge with IPB if i have done your mod on my coppermine?
Title: Re: Permanant watermark with undo possibility (GD2+IMagick) for 1.4.3
Post by: Stramm on March 06, 2006, 08:35:01 am
it's a commercial software. I don't know it and can't write/ modify a brisge for it. There are only a few changes necessary but for that bridge you're on your own
Title: Re: Permanant watermark with undo possibility (GD2+IMagick) for 1.4.3
Post by: cheenamalai on March 06, 2006, 03:22:40 pm
Well could you give me guidance on how to bridge it on my own? Since i am not capable of doing that.
Title: Re: Permanant watermark with undo possibility (GD2+IMagick) for 1.4.3
Post by: TBoomer on March 20, 2006, 07:57:10 pm
Hello @ll,

I just tried this mod with a 'clean' install of version 1.4.4 - on my play-server at home...

The mod does not work at all, and there are no error-messages at all :-(((

Someone has any hints?

Greets,
TBoomer
Title: Re: Permanant watermark with undo possibility (GD2+IMagick) for 1.4.3
Post by: Stramm on March 20, 2006, 08:52:35 pm
TheGamer1701 tried to port my watermark mod to 1.4x... but if you've read post one you'd know that he didn't succeed yet
Title: Re: Permanant watermark with undo possibility (GD2+IMagick) for 1.4.3
Post by: Cha83 on March 22, 2006, 10:18:09 pm
I am running cpg 1.4.3 and i want to use the permanent watermark mod from Stramm. I don't want to install the whole modpack cause i made some changes on my own and the last time i tried to install the modpack my whole gallery crashed ;)(so i need something like: find this: add after:). Can someone tell me what to do know ;) ?
Title: Re: Permanant watermark with undo possibility (GD2+IMagick) for 1.4.3
Post by: scunek on January 08, 2008, 10:20:22 pm
me install this mod for coppermine 1.4.14
when I have the problem I uplod the picture e.g. this coppermine reduces 1500px x 1500px about the size 2mb them to 1024px and 300kb but he shows  2mb  in the profile users farther and not 300kb how to improve this. Do I apologize too my weak English
Title: Re: Permanant watermark with undo possibility (GD2+IMagick) for 1.4.3
Post by: Stramm on January 09, 2008, 09:00:43 am
before a image gets watermarked, the system creates a backup copy of it. This copy (if existes) gets used for all calculations (width/ height and the ratio, image size, exif etc)

So the original copy has that 2mb from your example
Would mean some code changes and probably introduce some problems if you want to use the fullsized as reference
Title: Re: Permanant watermark with undo possibility (GD2+IMagick) for 1.4.3
Post by: scunek on January 09, 2008, 05:58:27 pm
to do so that orig_ would not by not to be created what ?
Title: Re: Permanant watermark with undo possibility (GD2+IMagick) for 1.4.3
Post by: Stramm on January 09, 2008, 06:55:27 pm
you can modify the code not to create the orig_ ... somewhere in this thread I guess