Permanent Watermark with GD2 - Page 3 Permanent Watermark with GD2 - Page 3
 

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

Permanent Watermark with GD2

Started by Sammy, March 05, 2004, 07:53:14 PM

Previous topic - Next topic

0 Members and 4 Guests are viewing this topic.

uny

hi, I just install the Newest MOD. I get the following erro

Parse error: parse error, expecting `','' or `';'' in /usr/home/ushuaren/public_html/gallery/config.php on line 297

I appreciate your help!

uny

Quote from: "uny"hi, I just install the Newest MOD. I get the following erro

Parse error: parse error, expecting `','' or `';'' in /usr/home/ushuaren/public_html/gallery/config.php on line 297

I appreciate your help!

Problem fixed, but I have another two questions:

1. I just noticed that all the sudden, all the YES and NO settings in the Setting can't be chose.

I can't select Neither Yes or No.  it's all Blank.

2. If I add some new images to the album, after I upload them, is there a way to Watermark the NEW images only?

Please let me know the solution if there is any!
Thanks for your MOD!

Joachim Müller

you haven't applied the mod correctly. Undo all your modifications (restore the files from the original coppermine package if necessary) and re-apply the mod.

GauGau

uny

Quote from: "gaugau"you haven't applied the mod correctly. Undo all your modifications (restore the files from the original coppermine package if necessary) and re-apply the mod.

GauGau

Thanks GauGau for your reply, but all I did is Upload the PHP adn SQL file that he included in the ZIP file, no Manually edit except Overwrite the file and the SQL command.

any other suggestions?

Thank you!  :)

Sammy

@uny

What is Your Coppermine version?
It should be newest version 1.2.1.

I have now modified 6 coppermine galleries to GD" watermarking with out any problem.

I try do that normal_ image size check to this modification on weekend.

Tarique Sani

@Sammy - the 1.3 release is almost final now - I would suggest whatever you do now onwards should be for version 1.3
SANIsoft PHP applications for E Biz

Sammy

@Tarique

Great to hear about 1.3 version!
I will wait for it.

photoman13

Sammy.. I wanna thank ya again.. your watermarking is working just great for me :):)

Sammy

Quote from: "photoman13"Sammy.. I wanna thank ya again.. your watermarking is working just great for me :):)
You're welcome!
Nice to here that it's working fine for You.

kudde6

Sammy,

Does this hack also work for version 1.3.0? did you allready test that?

Regards,
K.D.
Kind regards,
K.D.

Sammy

@kudde6

I dont know if it will work. I dont have 1.3 yet :(

Last time when I was trying to find 1.3, it was still available for those testers only. Now it seems to be available on public for a month ?  :oops:  :oops:  :oops:


I'll try it.....

kudde6

HI Sammy,

Any chance that you have tested it ?

Regards,
Kudde6
Kind regards,
K.D.

Joachim Müller

why don't you test it for the community and let us know your test results ;)

GauGau

darkcool

this was a great mod I would said.

There is something I would suggest the author of this hack or some one familiar with this hack to think into. When ever the watermark is applied the exif information in the JPEG somehow got delete. I don't know if it possible that the image to have the Exif and still have the watermark on them.


Thanks for this great mod.

Burpee

Quote from: Tarique Sani on March 26, 2004, 11:14:03 AM
Can you zip up the relevant files and post a link OR sent it to me

I will incorporate it into the main CPG (of course your name will be in the credits)

Do you guys plan on putting it into CPG 1.3 standard?
Would love to see that.
Permanent Watermark with GD2 + CPG 1.3 = my Dream CPG

hoggwild

Great mod Sammy:

Does anyone have this active so that I may see the albums with the watermark?

Burpee


photoman13

Quote from: hoggwild on April 30, 2004, 04:55:08 PM
Great mod Sammy:

Does anyone have this active so that I may see the albums with the watermark?

It's active on 2 of my sites :)

http://www.ericjon.com/photoserver

&

http://www.richiebrown.net/gallery

Burpee

#58
I decided to "modify" this mod so it'll work in CPG 1.3 and my brother helped me fix the "_normal" bug

Permanent Watermark with GD2 MOD


For CPG users who wants to add GD2 watermark function on their gallery.

This MOD uses GD2!

Here is how to mod CPG 1.3 to be able to add watermark automatically on new pics and by choise on all pics in selected album.
This is quite long post, but it takes only about 10 minutes to add this mod

Files that needs to be modified:
Lang/english.php
include/picmgmt.inc.php
util.php
config.php
(and 4 SQL command to execute)


REMEMBER to take backup from all files that You are modifying


1.
Open file Lang/english.php

Find this:'th_wd' => 'Width',

Add this after it

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


Find this:

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


Add this after it


              'Image watermarking',
              array('Watermark Image on upload', '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),

             
Find this:  'delete_orphans' => 'Delete orphaned comments (works on all albums)',

Add this a line after it
       'watermarks' => 'Add watermaks',
       'watermark_normal' => 'Resized images only',
       'watermark_image' => 'Original sized only',
       'watermark_both' => 'Original and resized images',
       'watermark_wait' => 'Watermarking images...',
       'watermark_continue_wait' => 'Continuing to watermarking originals and/or resized images...',



2.
Open file include/picmgmt.inc.php

Find this:$image_filesize = filesize($image);

Add this before it
      //Adds watermarks to new images
      if ($CONFIG['enable_watermark'] == '1' && $CONFIG['which_files_to_watermark'] == 'both' || $CONFIG['which_files_to_watermark'] == 'original') {
              if (!watermark($image))  //this is for full size image
                      return false;
      }
      if ($CONFIG['enable_watermark'] == '1' && $CONFIG['which_files_to_watermark'] == 'both' || $CONFIG['which_files_to_watermark'] == 'resized') {
      if (file_exists($normal) && !watermark($normal))  //this is for intermediate size image
          return false;
      }
               

The following line has been modified to fix the the "_normal bug"
      if (file_exists($normal) && !watermark($normal))  //this is for intermediate size image



Find this:?> (or end of picmgmt.inc.php)

Add this before it
       /**
        * watermark_image()
        *
        * Create a file containing a watermarked 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  //ainoastaan gd2
        * @return 'true' in case of success
        */
       function watermark($src_file)
       {
           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) {
               $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($ratio, 1.0);*/
           $destWidth = $srcWidth; //(int)($srcWidth / $ratio);
           $destHeight = $srcHeight; //(int)($srcHeight / $ratio);

                       $dest_file = $src_file;
           // Method for thumbnails creation
       //    switch ($method) {
       //        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;
                   } //duunataan wesileima
                   $dst_img = imagecreatetruecolor($destWidth, $destHeight);
                                       /*$dst_img =*/   ImageAlphaBlending($dst_img, true) or die ("Could not alpha blend"); // Enable when on GD 2+
                  imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $destWidth, (int)$destHeight, $srcWidth, $srcHeight);
                                  $logoImage = ImageCreateFromPNG($CONFIG['watermark_file']);
                                       $logoW = ImageSX($logoImage);
                                       $logoH = ImageSY($logoImage);
                                       //where is the watermark displayed...
                                       $pos = $CONFIG['where_put_watermark'];
                                       if ($pos == "topleft") {
                                       $src_x = 5;  
                                       $src_y = 5;
                                       } else if ($pos == "topright") {
                                       $src_x = $srcWidth - ($logoW + 5);
                                       $src_y = 5;
                                       } else if ($pos == "bottomleft") {
                                       $src_x = 5;
                                       $src_y = $srcHeight - ($logoH + 5);
                                       } else if ($pos == "bottomright") {
                                       $src_x = $srcWidth - ($logoW + 5);
                                       $src_y = $srcHeight - ($logoH + 5);
                                       }

                                       ImageCopy($dst_img,$logoImage,$src_x,$src_y,0,0,$logoW,$logoH); //$dst_x,$dst_y,0,0,$logoW,$logoH);
                   imagejpeg($dst_img, $src_file, $CONFIG['jpeg_qual']);
                   imagedestroy($src_img);
                   imagedestroy($dst_img);
               //    break;
           //}
           // Set mode of uploaded picture
           // We check that the image is valid
           $imginfo = getimagesize($src_file);
           if ($imginfo == null) {
               $ERROR = $lang_errors['resize_failed'];
               @unlink($src_file);
               return false;
           } else {
               return true;
           }
       }




3.
Open File util.php

Find this: function deleteorig()

Add this before it
function vesileimaathumbit()   //watermarkthumbs
{
   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);

   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) {
       $image = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") . mysql_result($result, $i, "filename");

       if ($updatetype == 0 || $updatetype == 2) {
           $imagesize = getimagesize($image);
           if (max($imagesize[0], $imagesize[1]) > $CONFIG['picture_width'] && $CONFIG['make_intermediate'])        {
           $image = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") . $CONFIG['normal_pfx'] . mysql_result($result, $i, "filename");
                       }        else        {
           $image = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") . mysql_result($result, $i, "filename");
                       }

           if (watermark($image)) {
               print $image .' '. $lang_util_php['updated_succesfully'] . '!<br />'; //$normal .' '. $lang_util_php['updated_succesfully'] . '!<br />';
               my_flush();
           } else {
               print $lang_util_php['error_create'] . ':$image<br />'; //$lang_util_php['error_create'] . ':$normal<br />';
               my_flush();
           }
       }

       if ($updatetype == 1 || $updatetype == 2) {
           $image = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") . mysql_result($result, $i, "filename");

           if (watermark($image)) {
               print $image .' '. $lang_util_php['updated_succesfully'] . '!<br />'; //$normal .' '. $lang_util_php['updated_succesfully'] . '!<br />';
               my_flush();
           } else {
               print $lang_util_php['error_create'] . ':$image<br />'; //$lang_util_php['error_create'] . ':$normal<br />';
               my_flush();
           }
       }

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

   if ($startpic < $totalpics) {

       ?>
           <form action=<?php echo $phpself;
        
?>
method="post">
                   <input type="hidden" name="action" value="continuewatermarks" />
                   <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
    
}
}  



Find this:updatethumbs();

Add this after it

   echo '<br /><a href="' . $phpself . '">' . $lang_util_php['back'] . '</a>';
} else if ($action == 'watermarks') {//tämä
   global $picturetbl, $CONFIG;
   print '<a href="' . $phpself . '">' . $lang_util_php['back'] . '</a><br />';
   print '<h2>' . $lang_util_php['watermark_wait'] . '</h2>';

   vesileimaathumbit();  //watermarkthumbs

   echo '<br /><a href="' . $phpself . '">' . $lang_util_php['back'] . '</a>';
} else if ($action == 'continuewatermarks') {//tämä
   print '<a href="' . $phpself . '">' . $lang_util_php['back'] . '</a><br />';
   print '<h2>' . $lang_util_php['watermark_wait'] . '</h2>';

   vesileimaathumbit();  //watermarkthumbs


Find this:starttable('100%', '<input type="radio" name="action" value="title" id="title" class="nobg"
(only part of that line)

Add this before it
//This is for watermarking
   starttable('100%', '<input type="radio" name="action" value="watermarks" id="watermarks" class="nobg" /><label for="watermarks" accesskey="w" class="labelradio">' . $lang_util_php['watermarks'] . '</label> (1)');
   print '
<tr><td>
' . $lang_util_php['update_what'] . ' (2):<br />
<input type="radio" name="updatetype" value="0" id="thumb" class="nobg" /><label for="thumb" accesskey="w" class="labelradio">' . $lang_util_php['watermark_normal'] . '</label><br />
<input type="radio" name="updatetype" value="1" id="resized" class="nobg" /><label for="resized" accesskey="r" class="labelradio">' . $lang_util_php['watermark_image'] . '</label><br />
<input type="radio" name="updatetype" value="2" checked="checked" id="all" class="nobg" /><label for="all" accesskey="a" class="labelradio">' . $lang_util_php['watermark_both'] . '</label><br />
' . $lang_util_php['update_number'] . '
<input type="text" name="numpics" value="' . $defpicnum . '" size="5" /><br />
' . $lang_util_php['update_option'] . '<br /><br />
</td></tr>';
   endtable();

   print '<br />';




4.
Open file config.php

Find this:function create_form(&$data)

Add this above it
// Added for allowing user to select where to add watermarks on pics...
function form_watermark($text, $name)
{
   global $CONFIG, $lang_config_php;

   $value = $CONFIG[$name];
   $bottomright_selected = ($value == 'bottomright') ? 'selected' : '';
   $bottomleft_selected = ($value == 'bottomleft') ? 'selected' : '';
   $topleftt_selected = ($value == 'topleftt') ? 'selected' : '';
   $topright_selected = ($value == 'topright') ? 'selected' : '';

   echo <<<EOT
       <tr>
           <td class="tableb">
                       $text
       </td>
       <td class="tableb" valign="top">
                       <select name="$name" class="listbox">
                               <option value="bottomright" $bottomright_selected>{$lang_config_php['wm_bottomright']}</option>
                               <option value="bottomleft" $bottomleft_selected>{$lang_config_php['wm_bottomleft']}</option>
                               <option value="topleftt" $topleftt_selected>{$lang_config_php['wm_topleftt']}</option>
                               <option value="topright" $topright_selected>{$lang_config_php['wm_topright']}</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 isdie('Invalid action');

Now we need to paste this
              //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;
              default:
between them.

After You have done it, it should look like this (I have put couple lines befor and after those lines in this example (hoppe You got it, becouse of My poor english :?
               // tabbed display fix
               case 10 :
                   form_number_dropdown($element[0], $element[1]);
                   break;

              //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;
              default:
                   die('Invalid action');
           } // switch
       } else {
           form_label($element);



5.
Then You need to execute theese SQL commands with phpMyAdmin or Webmin, etc.

insert into cpg11d_config (name, value) values ('enable_watermark', '1');
insert into cpg11d_config (name, value) values ('where_put_watermark', 'bottomright');
insert into cpg11d_config (name, value) values ('watermark_file', '/your/full/path/to/logo.png');
insert into cpg11d_config (name, value) values ('which_files_to_watermark', 'both');



Thats it. Now You can go to settings and set it up.
Actually You need to go there, before trying to add new pics.
You have to change 'Which file to use for watermark' to point to your own logo.png file that is used as watermark.


This should contain every modification I have made.

Tarique Sani

And a zip file with the mod is located at? :D

Great work - thanks
SANIsoft PHP applications for E Biz