Permanant watermark with undo possibility (GD2+IMagick) Permanant watermark with undo possibility (GD2+IMagick)
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

Permanant watermark with undo possibility (GD2+IMagick)

Started by Stramm, March 26, 2005, 06:09:36 PM

Previous topic - Next topic

0 Members and 7 Guests are viewing this topic.

Stramm

This mod is based on the 'Permanent Watermark with GD2 mod'.
However I've rewritten the entire thing cause I didn't like the drawbacks of original 'Permanent Watermark with GD2 mod'
That mod did image resize -> save -> image resize -> save -> watermark -> save
with each step losing image quality... and an unnecesary load on the box

so that's fixed


hacks of the mod to be found in this thread:
- admin can disable watermarking whilst upload (checkbox added to upload form)
- possibility to assign different watermarks to certain users.
- better admin tool to add/ remove/ update watermarks to thumbs/ normal/ full images

added
a) an undo function. If you want to get rid of your watermarks or apply new ones. No problem. You can do that without any loss in image quality or having 2,3,4 watermarks on the image
b) watermarks can be transparent (so you can see the original image through it)
c) supports imagemagick and GD2
d) watermark can be in the center now as well
modified
in config Watermark Image on upload has been changed to Watermark Image
-> it's global now. So in Admin Tools just use 'Update thumbs and/or resized photos' to apply or remove watermarks
added a new function in Admin Tools as well if you want to delete the backup images... however then you won't be able to undo watermarks. If no watermarks are actually applied.. no problem. Go ahead and delete them. If you later create watermarks it auto creates backup images.

If you upload pictures and watermarking is disabled then no backup images get created. Only if you enable watermarking. So it doesn't waste a lot of HD

The advantage of watermarking is that full sized images get compressed. So if you upload a 2000x1000 digicam picture it may have 1.5+mb. When watermarking it get's compressed down to ~300k (depending on image quality you've set) saving you a lot of bw.

The settings in Coppermine config:
Watermark Image - Yes/No
Where to place the watermark - select a spot where your watermark should appeare
Which files to watermark - normal sized, full sized or both
Which file to use for watermark - enter full path to your watermark image
note:
GD2 needs a png (24)
Imagemagick -> jpg, gif, png with the last two you can have a transparent background
So just create in PS a Text in a second layer, delete to bg layer and save as gif or png transparent. If you use png take 24bit otherwise you'll have funny results (with GD2)

Transparency 0-100 for entire image - makes the entire watermark transparent to the bg (100 for no transparency)
Set color transparent x,y (GD2 only) - if you want to enable this uncomment the following line in picmgmnt.inc.php

//imagecolortransparent($logoImage, imagecolorat($logoImage, $CONFIG['watermark_transparency_featherx'], $CONFIG['watermark_transparency_feathery']));


what it does... if you haven't created a png with a transparent background but a white one you can select the color white (you need to know the coordinates where white appeares on the watermark, usually 1,1 fits) and GD renders white fully transparent

If it works for you as it's doing for me... or if you have problems... --> feedback appreciated

Stramm

#1
If you're using GD2 with PHP5... and your watermark doesn't look very pretty have a look here http://forum.coppermine-gallery.net/index.php?topic=16286.msg98094#msg98094

life demo (online when I'm working, register without email confirmation) http://stramm.mine.nu

downloadable already edited files http://forum.coppermine-gallery.net/index.php?topic=21469.0

so let's start

first the necessary SQL
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');


now open lang/english.php
find
$lang_config_php
and add

 'wm_bottomright' => 'Bottom right',
 'wm_bottomleft' => 'Bottom left',
 'wm_topleft' => 'Up left',
 'wm_topright' => 'Up Right',
 'wm_center' => 'Center',
 'wm_both' => 'Both',
 'wm_original' => 'Original',
 'wm_resized' => 'Resized',


after
array('Display notices in debug mode', 'debug_notice', 1), //cpg1.3.0
add

'Image watermarking',
array('Watermark Image', 'enable_watermark', 1),
array('Where to place the watermark', 'where_put_watermark', 11),
array('Which files to watermark', 'which_files_to_watermark', 12),
array('Which file to use for watermark', 'watermark_file', 0),
array('Transparency 0-100 for entire image', 'watermark_transparency', 0),
array('Set color transparent x (GD2 only)', 'watermark_transparency_featherx', 0),
array('Set color transparent y (GD2 only)', 'watermark_transparency_feathery', 0),



after
'delete_orphans' => 'Delete orphaned comments (works on all albums)',   
add

 'update_full' => 'Both normal and full sized (if a orig copy is available)',
 'delete_back' => 'Delete original image backup (if you do that you can not undo watermarking)',


in
$lang_delete_php
add
 'orig_pic' => 'original image',



now we change config.php
above
function create_form(&$data)




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



Find this:

               case 10 :
                   form_number_dropdown($element[0], $element[1]);
                   break;


Few lines below is
Code:
die('Invalid action');
Now we need to paste this code in between

              //Watermark place
              case 11 :
                  form_watermark($element[0], $element[1]);
                                      break;
              //Which filest to watermark
              case 12 :
                  form_watermark2($element[0], $element[1]);
                                      break;
              case 13 :
                  // do nothing
                  break;



open util.php   

after        
' . $lang_util_php['update_what'] . ' (2):<br />

add below some similar lines
<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 />

a few lines below
find
   starttable('100%', '<input type="radio" name="action" value="delnorm" id="delnorm" class="nobg" /><label for="delnorm" accesskey="e" class="labelradio">' . $lang_util_php['delete_original'] . '</label> (1)');
   endtable();
   print '<br />';


and below add

   starttable('100%', '<input type="radio" name="action" value="delback" id="delback" class="nobg" /><label for="delback" accesskey="e" class="labelradio">' . $lang_util_php['delete_back'] . '</label> (1)');
   endtable();
   print '<br />';



find    deleteorig();
and after add



   echo '<br /><a href="' . $phpself . '">' . $lang_util_php['back'] . '</a>';
} else if ($action == 'delback') {
   print '<a href="' . $phpself . '">' . $lang_util_php['back'] . '</a><br />';
   print '<h2>' . $lang_util_php['replace_wait'] . '</h2>';

   deletbackup_img();

   

find function deleteorphans() and above   
   

function deletbackup_img()
{
   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;
   }
}



replace the function updatethumbs() with (you need to delete the entire function... not only the name)

function updatethumbs()
{
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
    
}
}




now delete.php

find a block similar to the one below and replace (just colspan has been adjusted)
   // Picture

   case 'picture':
       if (!(GALLERY_ADMIN_MODE || USER_ADMIN_MODE)) cpg_die(ERROR, $lang_errors['access_denied'], __FILE__, __LINE__);

       $pid = (int)$HTTP_GET_VARS['id'];

       pageheader($lang_delete_php['del_pic']);
       starttable("100%", $lang_delete_php['del_pic'], 7);
       output_table_header();
       $aid = delete_picture($pid);
       output_caption();
       echo "<tr><td colspan=\"7\" class=\"tablef\" align=\"center\">\n";
       echo "<div class=\"admin_menu_thumb\"><a href=\"thumbnails.php?album=$aid\"  class=\"adm_menu\">$lang_continue</a></div>\n";
       echo "</td></tr>\n";
       endtable();
       pagefooter();
       ob_end_flush();
       break;



do the same with this block
<tr>
<td class="tableh2"><b>Picture</b></td>
<td class="tableh2" align="center"><b>F</b></td>
<td class="tableh2" align="center"><b>N</b></td>
<td class="tableh2" align="center"><b>O</b></td>
<td class="tableh2" align="center"><b>T</b></td>
<td class="tableh2" align="center"><b>C</b></td>
<td class="tableh2" align="center"><b>D</b></td>
</tr>
<?php
}

function 
output_caption()
{
 
   global $lang_delete_php
    ?>

<tr><td colspan="7" class="tableb">&nbsp;</td></tr>
<tr><td colspan="7" class="tableh2"><b><?php echo $lang_delete_php['caption'?></b></tr>
<tr><td colspan="7" class="tableb">
<table cellpadding="1" cellspacing="0">
<tr><td><b>F</b></td><td>:</td><td><?php echo $lang_delete_php['fs_pic'?></td><td width="20">&nbsp;</td><td><img src="images/green.gif" border="0" width="12" height="12" align="absmiddle"></td><td>:</td><td><?php echo $lang_delete_php['del_success'?></td></tr>
<tr><td><b>N</b></td><td>:</td><td><?php echo $lang_delete_php['ns_pic'?></td><td width="20">&nbsp</td><td><img src="images/red.gif" border="0" width="12" height="12" align="absmiddle"></td><td>:</td><td><?php echo $lang_delete_php['err_del'?></td></tr>
<tr><td><b>O</b></td><td>:</td><td><?php echo $lang_delete_php['orig_pic'?></td></tr>
<tr><td><b>T</b></td><td>:</td><td><?php echo $lang_delete_php['thumb_pic'?></td></tr>
<tr><td><b>C</b></td><td>:</td><td><?php echo $lang_delete_php['comment'?></td></tr>
<tr><td><b>D</b></td><td>:</td><td><?php echo $lang_delete_php['im_in_alb'?></td></tr>
</table>
</td>
</tr>



in function delete_picture($pid) find line similar to the following and replace
     $files = array($dir . $file, $dir . $CONFIG['normal_pfx'] . $file, $dir . $CONFIG['thumb_pfx'] . $file, $dir . $CONFIG['orig_pfx'] . $file);


Stramm

#2
the rest is easy
rename or delete the file include/picmgmt.inc.php

and create a file include/picmgmt.inc.php that contains


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





That's it... have fun

bug fix: in editpics.php find
                        $files=array($dir.$file, $dir.$CONFIG['normal_pfx'].$file, $dir.$CONFIG['thumb_pfx'].$file);

replace with
                        $files=array($dir.$file, $dir.$CONFIG['normal_pfx'].$file, $dir.$CONFIG['thumb_pfx'].$file, $dir.$CONFIG['orig_pfx'].$file);


in searchnew
            if (strncmp($file, $CONFIG['thumb_pfx'], strlen($CONFIG['thumb_pfx'])) != 0 && strncmp($file, $CONFIG['normal_pfx'], strlen($CONFIG['normal_pfx'])) != 0 && $file != 'index.html')

with
            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')


lancefiasco

#4
In Util.php...

ERROR creating:$thumb
ERROR creating:$normal
ERROR creating:$thumb
ERROR creating:$thumb
ERROR creating:$thumb
ERROR creating:$thumb

(w/ watermarking on)

When it's off, no problem.

Stramm

Quote from: lancefiasco on April 03, 2005, 03:17:27 AM
In Util.php...

ERROR creating:$thumb
ERROR creating:$normal
ERROR creating:$thumb
ERROR creating:$thumb
ERROR creating:$thumb
ERROR creating:$thumb

(w/ watermarking on)

When it's off, no problem.

Can you upload single pictures with watermarking enabled.
Just with that info I can't tell you much... except that it usually means the system can't find the source file from where to create the files. It's a simple process. It checks if there's a copy of the uploaded full size image and if it's there it's using it, otherwise it takes the full sized image.

So open include/picmgmt.inc.php and insert
echo "Source: $src_file --- Destination: $dest_file<br>";

after
function resize_image($src_file, $dest_file, $new_size, $method, $thumb_use, $watermark)
{
   global $CONFIG, $ERROR;
   global $lang_errors;


then run it again. Now it'll tell you what file it's using as source and what file it's updating. Knowing that it shouldn't be a problem to fix it.

Oh, and I've forgotten to ask what you're using, GD2 or IM, *nix or win

lancefiasco

Quote from: Stramm on April 03, 2005, 09:16:27 AM
Quote from: lancefiasco on April 03, 2005, 03:17:27 AM
In Util.php...

ERROR creating:$thumb
ERROR creating:$normal
ERROR creating:$thumb
ERROR creating:$thumb
ERROR creating:$thumb
ERROR creating:$thumb

(w/ watermarking on)

When it's off, no problem.

Can you upload single pictures with watermarking enabled.
Just with that info I can't tell you much... except that it usually means the system can't find the source file from where to create the files. It's a simple process. It checks if there's a copy of the uploaded full size image and if it's there it's using it, otherwise it takes the full sized image.

So open include/picmgmt.inc.php and insert
echo "Source: $src_file --- Destination: $dest_file<br>";

after
function resize_image($src_file, $dest_file, $new_size, $method, $thumb_use, $watermark)
{
    global $CONFIG, $ERROR;
    global $lang_errors;


then run it again. Now it'll tell you what file it's using as source and what file it's updating. Knowing that it shouldn't be a problem to fix it.

Oh, and I've forgotten to ask what you're using, GD2 or IM, *nix or win

ImageMagick on Linux

And, no, I cannot upload single pictures with watermarking enabled.

I'm going to try what you said, and then report back.

lancefiasco

Warning: Missing argument 6 for resize_image() in /home/gcfiasco/public_html/include/picmgmt.inc.php on line 134
Source: ./albums/edit/mHTTP_temp_2ac88500.jpg --- Destination: ./albums/edit/preview_14f1dd66.jpg

Stramm

the error you got doesn't matter at all... but you can fix it with replacing the function resize_image line with

function resize_image($src_file, $dest_file, $new_size, $method, $thumb_use, $watermark="false")

or just copy/ paste picmgmt.inc.php from above. It's fixed there

when you've added the echo line I told you what does it spit out and do the images it tells you exist?? From most interest are the images orig_something.jpg (that's when you do the batch stuff)

lancefiasco

Source: albums/userpics/10001/orig_108.jpg --- Destination: albums/userpics/10001/thumb_108.jpg
Source: albums/userpics/10001/orig_108.jpg --- Destination: albums/userpics/10001/normal_108.jpg
Source: albums/userpics/10001/orig_108.jpg --- Destination: albums/userpics/10001/108.jpg

Is that what you're looking for?

All those files exist...still no watermark.

Stramm

That all sounds pretty much OK :)
So my guess is that either the path to your watermark image is wrong or that it's a wrong format (I hope you use png... that's working perfect). But really, check the path, it has to be the absolute, full path to your watermark image

to check that add
if(!is_image($CONFIG['where_put_watermark'])) cpg_die(ERROR, "Watermark file not found or no image!!", __FILE__, __LINE__);

above (~line 180+ in picmgmt.inc.php)
$cmd = "{$CONFIG['impath']}composite -dissolve {$CONFIG['watermark_transparency']} -gravity {$CONFIG['where_put_watermark']} {$CONFIG['watermark_file']} $im_dest_file $im_dest_file";
and run the batch tool

if this is not the problem check if the composite command can be executed

lancefiasco

#11
"Watermark file not found or no image!!"

I have it set to "/images/watermark.png"...

I also tried "images/watermark.png" as well as "http://www.gcfiasco.com/images/watermark.png".

Tranz

You might need the full absolute path. Ask your webhost for details.

Stramm

lol, OK, a long story for a simple mistake...
you need the absolute server path.. what you give it is the relative path

save that as eg docroot.php
<?php
echo $_SERVER['DOCUMENT_ROOT'];
?>


upload it and run it.. it tells you the absolute path to your document root. To that add your coppermine dir and the image dir + watermark filename

eg it spits out /usr/home/Yourname/sites/yoursite.com/htdocs
then add to that path eg /coppermine/images/watermark.png

so you get teh absolute pyth to your watermark image
/usr/home/Yourname/sites/yoursite.com/htdocs/coppermine/images/watermark.png
easy, huh

Have fun

lancefiasco

Changed to /home/gcfiasco/public_html/images/watermark.png, and it STILL gives me that same error. :(



Stramm

it'S strange.. but I have no clue how your box is setup. If it's a forbidden error you can try 777 too or you change the owner to www (usually php in in that group) and php maybe setup to not be able to read other group files (for security reasons, usually when your on a shared box).

Here I can't help you any further. That's nothing to do with the script but with server setup. You should ask your support or, as said chmod to 777 and chown to www (or in whatever group php may be)

Stramm

and it now doesn't die anymore with a wrong path to watermark image error?? (in batch tool)