forum.coppermine-gallery.net

No Support => Modifications/Add-Ons/Hacks => Mods: Watermarking & image manipulation => Topic started by: skybax on August 14, 2004, 10:44:29 pm

Title: Another watermark mod (simpliest available) GD2 compatiable
Post by: skybax on August 14, 2004, 10:44:29 pm
I needed a simple watermarking hack to accomplish the following:

- Compatible with GD 2.0
- On the fly watermarking
- Non server intensive
- Customize expansion
- Identify individual images to watermark
- PNG input/output support

I wanted to be able to specify which images to watermark indivually within an album. I needed to also make sure that the watermark didn't swamp the main image. I also wanted a quick way to adjust the positioning of the watermark on the image.

The way this mod works is evaluates the user1 field to determine if image is to be watermarked. If 'yes' then it sends the image uri to the watermark class to be evaluated if the images is to small for watermark, if not it watermarks the file and save a copy to a determined folder. When the image is called a second time instead of creating a new file it pulls the created watermarked image and sends this back to the image display as a src. Any serious errors will stop the script and give descriptive results of the problem.

Planned future updates:
- Modify config to turn watermark on/off.
- Allow for evaluation of watermarked file date to allow for watermark updates
- Customizable setup from browser/integrate with dbase

1) First create a PNG watermark and upload it into the main images folder.

2) Ok, onto the code. *don't forget to backup all files being modified.
Open functions.inc.php and find:
Code: [Select]
return $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);
comment the code out (incase you decide to go back or the mod breaks while installing).

Add as a new line below commented code:
Code: [Select]
if ($pic_row['user1']!="YES") {

return $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);

} else {
require_once "include/watermark.class.php";
$watermark_file_location = 'images/watermark.png';
$picture_location = $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);;

$img = new Watermark();
$img->watermark_file = $watermark_file_location;
    $img->add_watermark($picture_location);
return $img->image_tag;


}

3) Create a file called watermark.class.php save this into the include folder, insert the following code and save:
Code: [Select]
<?php
    
/**
    * Custom Watermark Class for PNG or JPG watermarks with GD2
* Modified for use with Coppermine Image Gallery http://coppermine.sourceforge.net
    *
    * Usage Example:
Find in functions.inc.php:
return $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);

Replace with:
if ($pic_row['user1']!="YES") {

return $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);

} else {
require_once "include/watermark.class.php";
$watermark_file_location = 'images/watermark.png';
$picture_location = $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);;

$img = new Watermark();
$img->watermark_file = $watermark_file_location;
    $img->add_watermark($picture_location);
return $img->image_tag;


}
*
*
* @hacked   Timothy Wood <info@skybax.com>
* @Idea from SmartThumb http://www.fullo.net/progetti/smartthumb/
    * @authors to Philipp v. Criegern <criegep@criegern.com> & Francesco Fullone <ffullone@progettoaroma.com>
*
    * @version  1.0 8/8/2004 (hacked)
    */
    
class Watermark
    
{
        
/**
        * Directory where the created watermarked images are stored in (for PHP access)
        * e.g. '/usr/local/apache/htdocs/images/watermark'
        */
        
var $thumbnail_dir_internal  =  '/home/erotic/public_html/wmarked/';
        
/**
        * Path to watermarked directory for browser/coppermine access
        * e.g. '/images/thumbnails'
        */
        
var $thumbnail_dir_external  =  '../wmarked/';
 /**
        * Watermarked image suffix for new watermarked image
        * e.g. 'watermarksuffix_orginal.jpg'
        * WARNING: Cannot be left blank
        */
var $file_suffix 'watermark_';
        
/**
        * Error message if creation fails, this will crash the gallery for the particular image if all fails...
        */
        
var $error;
        
/**
        * where the watermark is inserted
        * topleft, bottomleft, topright, bottomright
        */
var $watermark_position "bottomright";
        
/**
        * the watermark filename
* currently MUST be a PNG24 file! working on gif/jpg support
        */
var $watermark_file;
        
/**
        * which kind of output is request
        * valid value is JPG, PNG*
*    * if using PNG - look @ www.skybax.com for more information on how to secure images 
*      (neat transparency effect that disables 'easy' harvesting of images)
        */
var $extension = 'JPG';
        
/**
* this method REQUIRES the GD 2.0+
        * @param string $imagefile Filename of source image
        */
        
function add_watermark $imagefile )
        {
if ((is_file($this->watermark_file)) && (function_exists('imagecreatetruecolor')))
{
$this->image_name  =  $this->file_suffix.basename($imagefile);
$this->image_tag  =  $imagefile;
if (!is_file($this->thumbnail_dir_internal $this->image_name)) 
{
$old $this->image_info($imagefile);

$logo ImageCreateFromPNG($this->watermark_file) or die($this->watermark_file.' is not a valid PNG24 file!');
$logo_w imagesX($logo); 
$logo_h imagesY($logo); 

// Check that image to be modified will not be swamped by watermark. (image has to be twice the size of the watermark)f
$original $this->image_info($imagefile);
$original_w imagesX($old); 
$original_h imagesY($old);
if ($original_w > ($logo_w 2) && $original_h > ($logo_h 2)){
if (strtoupper($this->watermark_position) == "TOPLEFT"
{
$src_x 0;
$src_y 0;

elseif (strtoupper($this->watermark_position) == "TOPRIGHT"
{
$src_x $this->width $logo_w;
$src_y 0;

elseif (strtoupper($this->watermark_position) == "BOTTOMLEFT"
{
$src_x 0;
$src_y $this->height $logo_h;

elseif (strtoupper($this->watermark_position) == "BOTTOMRIGHT"
{
$src_x $this->width $logo_w;
$src_y $this->height $logo_h;
}
else 
{
die ('the watermark position: ' $this->watermark_position ' is non recognized! try with: TOPLEFT, BOTTOMLEFT, TOPRIGHT, BOTTOMRIGHT');
}

$new  =  imagecreatetruecolor($this->width$this->height);

ImageAlphaBlending($newtrue) or die ("Could not alpha blend");
ImageCopy($new$old0000$this->width$this->height);
ImageCopy($new$logo$src_x$src_y00$logo_w$logo_h);    

$this->save_image($new);

ImageDestroy($new);
ImageDestroy($old);
ImageDestroy($logo);
}else{ return $img->image_tag; }
// $img->image_tag;

}
else
{
$arr  =  getimagesize($this->thumbnail_dir_internal $this->image_name);
$this->width   =  $arr[0];
$this->height  =  $arr[1];
}
//place $this->image_tag in the SRC of <img> 
$this->image_tag  =  $this->thumbnail_dir_external $this->image_name ;
}
else { die('Watermarking file: '$this->watermark_file.' did not work!'); }
}

 
/**
        * check the directory and update the class var
        */
function check_conf() 
{
     if (strlen($this->thumbnail_dir_internal)  &&  (substr($this->thumbnail_dir_internal, -1) != '/'))
            {
                
$this->thumbnail_dir_internal  .=  '/';
            }
            if (
strlen($this->thumbnail_dir_external)  &&  (substr($this->thumbnail_dir_external, -1) != '/'))
            {
                
$this->thumbnail_dir_external  .=  '/';
            }

}

        
/**
        * check the imagefile info to create the correct image stream
        * @param $imagefile the image filename
        * @return $img the image stream
        */
function image_info($imagefile
{
$tmp_extension strtoupper(substr(basename($imagefile), -3));

if ( $tmp_extension == 'JPG' 
{
$img ImageCreateFromJPEG($imagefile) or die ("Could not create from JPEG");
}
elseif ( $tmp_extension == 'PNG' 
{
$img ImageCreateFromPNG($imagefile) or die ("Could not create from PNG");
}
else
{
die('the extension '.$tmp_extension.' is not valid, try with JPG or PNG images');
}

$this->width imagesX($img); 
$this->height imagesY($img); 
return $img;
}


        
/**
        * save the image to disk
        * @param $img the image stream
        * @return void
        */
function save_image($img
{
if (strtoupper($this->extension) == 'JPG' 
{
$this->image_name  =  substr($this->image_name0, -4) . '.jpg';
ImageJPEG($img$this->thumbnail_dir_internal $this->image_name);
}
elseif (strtoupper($this->extension) == 'PNG' 
{
$this->image_name  =  substr($this->image_name0, -4) . '.png';
ImagePNG($img$this->thumbnail_dir_internal $this->image_name);
}
else 
{
die('the extension '.$this->extension.' is not valid, try with JPG or PNG'); 
}
}
        
/**
        * delete a thumbnail or watermark file image from the thumbnail_dir_internal
        * @param $imagefile the image filename
        * @return void
        */
function delete_image($imagefile
{
$this->image_name  =  basename($imagefile);

if (is_file($this->thumbnail_dir_internal $this->image_name)) 
{
unlink($this->thumbnail_dir_internal $this->image_name);
}
else
{
die('file does not exist');
}
}
//end watermark class
?>


Hope this helps -T 8)
Tested with 1.3.1

Or download the zip:
Title: Re: [MOD] Another watermark mod (simpliest available) GD2 compatiable
Post by: Tarique Sani on August 15, 2004, 02:44:26 am
Kewl work - now only if someone would write a class for ImageMagick as well (hint ;) )

This is the correct way to do watermarking IMO
Title: Re: [MOD] Another watermark mod (simpliest available) GD2 compatiable
Post by: kegobeer on August 15, 2004, 05:46:28 am
Don't forget that the newest version of GD supports GIF read/write again - can you modify your watermark hack to check for GIF creation support and allow GIFs to be watermarked accordingly?  A simple check like this:

Code: [Select]
// Check for GIF create support >= GD v2.0.28
if ($method == 'gd2') {
  $gdinfo = gd_info();
  $gifsupport = $gdinfo["GIF Create Support"];
}

should suffice.  Just a matter of incorporating it into your hack I would think.
Title: Re: [CPG1.3.x]: Another watermark mod (simpliest available) GD2 compatiable
Post by: skybax on August 15, 2004, 05:00:07 pm
*kegobeer - sweat I'll work on incorporating it...

*Tarique - If i had access to ImageMagick, i would; but since i don't, i can't.
Title: Re: [CPG1.3.x]: Another watermark mod (simpliest available) GD2 compatiable
Post by: r00t on August 15, 2004, 09:51:30 pm
i can give you access to a server with imagemagick if you want
Title: Re: [CPG1.3.x]: Another watermark mod (simpliest available) GD2 compatiable
Post by: skybax on August 18, 2004, 06:06:45 pm
Thanks to mstralka, I have been able to integrate this into XP publisher and working on a feature to turn on/off watermarking site wide along with individual image watermarking capabilities. Here's what I have completed so far with the xp_publisher.

Title: Re: [CPG1.3.x]: Another watermark mod (simpliest available) GD2 compatiable
Post by: Mario1 on August 22, 2004, 05:46:05 pm
Hello,

The way this mod works is evaluates the user1 field to determine if image is to be watermarked. If 'yes' then it sends the image uri to the watermark class to be evaluated if the images is to small for watermark, if not it watermarks the file and save a copy to a determined folder. When the image is called a second time instead of creating a new file it pulls the created watermarked image and sends this back to the image display as a src. Any serious errors will stop the script and give descriptive results of the problem.

sorry, but my english is not very good.
I have do 1) -3) and then?
How can I start the mod?
Title: Re: [CPG1.3.x]: Another watermark mod (simpliest available) GD2 compatiable
Post by: skybax on August 23, 2004, 04:17:51 pm
If you follow the first post instructions it will walk you through setting up the watermark using the user1 fields. I am working on integrating this its own mod that is configurable throught the admin settings. I do not have that posted yet and am working with mstralka to finalize this. Maybe I misunderstood your question. If you have problems please post an error or how you setup this mod.

-T
Title: Re: [CPG1.3.x]: Another watermark mod (simpliest available) GD2 compatiable
Post by: Mario1 on August 24, 2004, 09:40:13 am
Thanks.
This is my new problem:

Warning: imagecreatefromjpeg(albums/bootstour_2003/thumb_Bootstour%20003.jpg): failed to open stream: No such file or directory in /www/xyz/fotos/include/watermark.class.php on line 176
Could not create from JPEG

this is the pic: (deleted)
this is the watermark: (deleted)
here is the script: (deleted)

What can I do?
Title: Re: [CPG1.3.x]: Another watermark mod (simpliest available) GD2 compatiable
Post by: Joachim Müller on August 24, 2004, 10:50:32 am
without further looking into this I suggest not using special chars nor spaces in a filename, that is what probably causes the error.

GauGau
Title: Re: [CPG1.3.x]: Another watermark mod (simpliest available) GD2 compatiable
Post by: skybax on August 24, 2004, 02:20:55 pm
GauGau is right - I'm working on list of requirements to post after I get the fix for xp_publisher right now. Still having issues integrating that. but any special characters aside from underscore (i.e. '~#*&....) will crash the watermarking script. It's best to have a naming convention where it's all lowcase and simple names.
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: crashnet on September 02, 2004, 03:43:15 am
Well...I added the scripts,files, and image to the proper places, but nothing shows up.  What would cause the new functionality to not even show up (no errors or anything).

I am currently and successfully using GD2 and used user1 for the watermark and have YES in that field.
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: erroneus on September 02, 2004, 12:55:42 pm
You might avoid some questions if you include in the instructions that editing values in watermark.class.php is required, and naming the watermark file to watermark.png. That can only be determined by actually looking through the code, which some people might not do. I personally didn't realize it right away. Just a thought.

Anyway, I too followed your instructions carefully, and nothing happens to a picture when i upload, no watermark, or errors. Where should I begin looking for the problem first? Has anyone else actually gotten this to work? Thanks in advance.
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: skybax on September 02, 2004, 02:13:59 pm
I'm in the process of switching this to have it's own custom field. So some of the code (ie xp publsiher) won't be adding the vallues to the right place. Also make sure that you turn on custom field 1 with the title of "watermark"
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: crashnet on September 03, 2004, 04:23:25 pm
I'm in the process of switching this to have it's own custom field. So some of the code (ie xp publsiher) won't be adding the vallues to the right place. Also make sure that you turn on custom field 1 with the title of "watermark"

So to fix the problem with the watermarks not showing up, I need to change custom field 1 to "watermark," no caps, nothing else?  Oh, and that would be fantastic if you could give it its own custom field, preferably one that only admins can see and not members/guests, etc.
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: erroneus on September 04, 2004, 11:46:15 pm
So to fix the problem with the watermarks not showing up, I need to change custom field 1 to "watermark," no caps, nothing else?

Correct. Then when you either upload or approve a picture, you'll see the watermark field under the "keywords" field. For the watermark field, enter YES in caps. That should get it working, assuming you configured all the values correctly in watermark.class.php. Also make sure the png file you put in cpgroot/images is named "watermark.png".
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: squish on September 06, 2004, 05:18:44 am
I've given this mod a try, followed all the instructions etc
However I keep getting this error message

"  Parse error: parse error, unexpected $ in /home/krice/public_html/pictures/include/functions.inc.php on line 1785 "

At first I thought maybe Dreamweaver was screwing things up, so I used notepad. Same error message.
I'm fairly new to Coppermine, is there something I'm not doing?
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: Joachim Müller on September 06, 2004, 05:45:29 am
post your code along those lines. When doing a copy'n paste from the board, there can be strange errors if you have spaces after
Code: [Select]
echo <<<EOT in a line or before/after
Code: [Select]
EOT;.

Joachim
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: squish on September 06, 2004, 06:04:35 am
Here is the code, I"ve pasted from  lines  1778 to 1785

Code: [Select]
return $return;
}





?>


Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: Casper on September 06, 2004, 09:40:51 am
This often means you have missed a curly brace '{' somewhere.

Looking at the mod, make sure you did not miss the one at the end of this addition;

Code: [Select]
if ($pic_row['user1']!="YES") {

return $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);

} else {
require_once "include/watermark.class.php";
$watermark_file_location = 'images/watermark.png';
$picture_location = $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);;

$img = new Watermark();
$img->watermark_file = $watermark_file_location;
    $img->add_watermark($picture_location);
return $img->image_tag;


}
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: skybax on September 06, 2004, 01:46:45 pm
I'm in the process of rewriting the code so that it has it's own field and can be controlled site wide via config. I am also working on adding hooks so that it can be writen in as a plugin once that is released in stable. Since I was out all last week from flooding and schedules I am getting back in the groove on testing the mods. I hope to release the finalized version sometime soon.

-T
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: squish on September 06, 2004, 06:41:31 pm
I managed to figure it out, when I was commenting out that first like, I also commented out the squiggle ( } ) that was right below it.

Thanks the help
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: crashnet on September 10, 2004, 09:16:36 pm
Well, I got it to say something, but each time I click on an image that I have applied the watermark to, I get ths error:

Quote
Watermarking file: images/watermark.png did not work!

The watermark image is in the right folder, the word "watermark" is in user1, and I checked and rechecked watermark.class.php.  I have to remove the mod in order to be able to view any of my images again.  What would cause this error?  Am I supposed to modify this stuff, and if so, can you be a little more detailed as of what you are asking to change these paths too.  The wording is a litte confusing.

Code: [Select]
class Watermark
    {
        /**
        * Directory where the created watermarked images are stored in (for PHP access)
        * e.g. '/usr/local/apache/htdocs/images/watermark'
        */
        var $thumbnail_dir_internal  =  '/home/erotic/public_html/wmarked/';
        /**
        * Path to watermarked directory for browser/coppermine access
        * e.g. '/images/thumbnails'
        */
        var $thumbnail_dir_external  =  '../wmarked/';
/**
        * Watermarked image suffix for new watermarked image
        * e.g. 'watermarksuffix_orginal.jpg'
        * WARNING: Cannot be left blank
        */
var $file_suffix = 'watermark_';
        /**
        * Error message if creation fails, this will crash the gallery for the particular image if all fails...
        */
        var $error;
        /**
        * where the watermark is inserted
        * topleft, bottomleft, topright, bottomright
        */
var $watermark_position = "bottomright";
        /**
        * the watermark filename
* currently MUST be a PNG24 file! working on gif/jpg support
        */
var $watermark_file;
        /**
        * which kind of output is request
        * valid value is JPG, PNG*
*    * if using PNG - look @ www.skybax.com for more information on how to secure images
*      (neat transparency effect that disables 'easy' harvesting of images)
        */
var $extension = 'JPG';
        /**
* this method REQUIRES the GD 2.0+
        * @param string $imagefile Filename of source image
        */

Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: trouble on September 12, 2004, 07:05:16 am
is it supposed to work on windows server? i ve done everything as described in this forum, but i get the following error when trying to view the image.

Warning: imagecreatefromjpeg(albums/userpics/10001/thumb_DSC00267%20%28Large%29.JPG): failed to open stream: No such file or directory in
D:\My Webs\anglija.com\webroot\album\include\watermark.class.php on line 176
Could not create from JPEG

any ideas?

------------

ok i fixed it. I will leave this post should it help anyone.
1. file name was a problem. it doesnt like filenames with anything in it, except basic charachters.
2. need to give write permission rigths to "wmarked" folder. In windows its done via security option on folder right-click menu.
3. had to change $thumbnail_dir_external variable to full path from root. dunno why it didnt like the original one. i changed it to:
var $thumbnail_dir_external  =  '/album/wmarked/';
4. i dont remember what else i done, sorry im a bit drunk.

any problems gimme a shout. i may be able to help. you can see my watermarks in action at http://www.anglija.com/album/displayimage.php?album=7&pos=1 :o)

would be kool if anyone could fix this problem with filenames. cause its really complicated to force everyone to upload pics with certain naming rules - its rather impossible.
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: trouble on September 12, 2004, 05:28:00 pm
anyone who has problems with file names, and want to use chars like: + = & - ( )  etc.. in file names, could use this quick fix solution:
in file "functions.inc.php" find a line:
"$picture_location = $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);;"

and insert this line straight after that:
$picture_location = rawurldecode($picture_location);

should do the trick.
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: erroneus on September 14, 2004, 01:11:24 pm
anyone who has problems with file names, and want to use chars like: + = & - ( )  etc.. in file names, could use this quick fix solution:
in file "functions.inc.php" find a line:
"$picture_location = $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);;"

and insert this line straight after that:
$picture_location = rawurldecode($picture_location);

should do the trick.

awesome! thanks! the filename problem was pretty much the only thing preventing me from using this great watermark mod. Will this allow filenames with spaces too now?
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: nugget on November 29, 2004, 08:03:00 pm
what do you mean with "comment the code out" sry my english is baad ;)
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: Tranz on November 29, 2004, 08:27:59 pm
Commenting methods depend on the code. Please specify where you saw that suggestion and which code it pertains to.
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: jojo3ep on December 26, 2004, 10:10:28 pm
I have installed this hacks, but even if I have followed all recommandations posted, no watermark is added to my picture even I hae added to user file 1 : yes !
What can I do ? I have to error message but as well no watermark ! Thanks
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: skybax on December 29, 2004, 08:09:12 pm
please provide a sample link and the code for the class you are using.

-T
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: irishblue on January 01, 2005, 12:53:47 pm
thanks for this mod! Got it working great.
Except it doesn't seem to appear on the portrait oriented pictures, only the landscape ones. Any idea how to fix that?
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: skybax on January 02, 2005, 09:54:01 pm
it should work - however it may depend on the size of your pictures - if the math determines the picture is too small so that your watermark doesn't engulf the image...

-T
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: irishblue on January 03, 2005, 09:05:04 am
ah ok thanks! :) Yeah might be that the image is too small.
Got another question, is the script supposed to watermark the thumbnails too?
I have a 1064 x 1600 pixels image, but only the full-sized version gets watermarked, but the thumbnail on the individual viewing (displayimage) page doesn't.

If its not supposed to, is it possible to set it to do so? perhaps use a smaller version or separate watermark image so it fits the thumbnail?
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: skybax on January 05, 2005, 04:44:06 pm
the script excludes the thumbnails because I found that watermarks looked really crappy shrunk - however it is possible... and you can set it up so that it uses a different wmark for the thumbnail you would just have to modify the code for dispalying the thumbnails... (theme.php i believe)
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: irishblue on January 05, 2005, 06:25:19 pm
is it possible to just get it to shrink the watermark together with the pic?
if so, which file should i make the changes to?
the separate watermark sounds complicated and i'm not very good with code  ???
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: Tranz on January 05, 2005, 06:42:53 pm
What you can do is, after watermarking the larger photos, go into admin tools. There is an option to regenerate the thumbnails. The new thumbnails will be using the watermarked files so the watermarks will show up on thumbnails. That's what happened to my files, though I did not want watermarks on my thumbnails.
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: irishblue on January 06, 2005, 08:20:03 am
i tried that once while experimenting with the sizes. I went into admin tools after watermarking and regenerated the thumbnails. and all the files even the actual sized ones were grabbing files from the e.g. userpic/10001 folder instead of the wmarked folder. so all ended up w/o watermarks.
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: atommyk on January 15, 2005, 12:19:29 pm
Quote
I wanted to be able to specify which images to watermark indivually within an album.
I don't know if this information can be found in your post, but is there a "standard-value" for the user1-field? Because if I undertand right, I would have to label each picture with user1-field "yes" manually - tell me that I'm wrong ;)
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: skybax on January 16, 2005, 03:42:27 am
you are correct about manually inputting all the value to turn on the watermarking feature.
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: davidshook on February 24, 2005, 05:04:02 am
I am sorry if this is answered somewhere in this thread allerady.
How exactly does this MOD work:
1) do all the batch uploaded pictures get watermarked?
-- or, do I get to chose if batch uploaded pictures get watermarked?

2)  do individual uploaded pictures get water marked?
-- do users/members (as opposed to admin level) have any control over the water marking process in this case.

3) what happens when a user uploads video, mp3, zip, pdf file?
-- does the upload faile?
-- does the file become unreadable?


The reason I am asking this is because I am designing a site that will have  a gallery that allows loged-in members to upload there own pictures/videos/documents. I want to have a watermark on the pictures that the users upload. The user should not be able to upload a picture without a water mark (although it is ok if they have a choice where to place the watermark on the picture)

The rest of the galleries are not for uploads by users. For these galleries I do the batch uploading and the pictures are already watermarked on my desktop pc prior to upload.

So, to some it up: all pictures that are uploaded via http/form need to be watermarked.
Batch files should not be watermarked.
Non-picture files should not be a problem (since I do not limit the file type to be uploaded)


I also think that anyone that thinks about using water marking should have these answers before going through the work of installing and testing the MOD's.

Please help, thank's in advance
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: kegobeer on February 24, 2005, 06:05:25 am
Have you reviewed all the posts in this thread?
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: tumnus on March 13, 2005, 03:14:31 pm
okay, i've had this hack working very nicely for a while.

Only thing i can't work out is (and here feel free to berate me for being a php idiot) where in the script can i tweak the JPEG quality of the watermarked images?
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: skybax on March 22, 2005, 10:54:07 pm
There is no place in the current script that modifies the jpg quality - it just returns the orginal image modified with the watermark added.... however if this feature is needed I am sure someone could add it so that it pulls from the config on jpg quality.

-T
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: bangerkcknbck on April 15, 2005, 09:12:22 pm
Hello.  I had 0 problems getting this mod to work.  Thank you very kindly for taking the time to create it.  I did however have a preference that I wanted to be able to watermark the image in the middle of the picture so it was hard to crop it out and retain a picture worth having.  I also wanted to be able to move the watermark down towards the bottom.  I added these parts into the watermark.class.php file.

I then needed to add the options to call where the placement of the watermark would be.  I added these in.
Code: [Select]
elseif (strtoupper($this->watermark_position) == "MIDDLE")
{
$src_x = $this->width/2 - $logo_w/2;
$src_y = $this->height/2  - $logo_h/2;
}
elseif (strtoupper($this->watermark_position) == "BOTTOMMIDDLE")
{
$src_x = $this->width/2 - $logo_w/2;
$src_y = $this->height - $logo_h - 80;
}

I had to also call this new placement.  Look for this line and change it to suit.
Code: [Select]
var $watermark_position = "BOTTOMMIDDLE";

If you want to change the vertical placment of "BOTTOMMIDDLE" just change the number to suit your needs.  The number to modify is the #80 where it says
Code: [Select]
$logo_h - 80;
I also wanted to post the entire set of code incase you wanted to copy/past it into your own watermark.class.php file.

Be forewarned I also modified the size requirements for the watermark.  Since I'm placing it in the middle I had to make sure the photo is bigger then the width of the watermark.  Instead of 2 times bigger then the watermark, the photo only needs to be 1.01 times wider and 1.01 higher and the watermark will be placed.

This is my first time ever changing code and posting the changes for others to use.  There may be a better way to do this and I welcome suggestions.
Code: [Select]
<?php
    
/**
    * Custom Watermark Class for PNG or JPG watermarks with GD2
* Modified for use with Coppermine Image Gallery http://coppermine.sourceforge.net
    *
    * Usage Example:
Find in functions.inc.php:
return $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);

Replace with:
if ($pic_row['user1']!="YES") {

return $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);

} else {
require_once "include/watermark.class.php";
$watermark_file_location = 'images/watermark.png';
$picture_location = $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);;

$img = new Watermark();
$img->watermark_file = $watermark_file_location;
    $img->add_watermark($picture_location);
return $img->image_tag;


}
*
*
* @hacked   Timothy Wood <info@skybax.com>
* @Idea from SmartThumb http://www.fullo.net/progetti/smartthumb/
    * @authors to Philipp v. Criegern <criegep@criegern.com> & Francesco Fullone <ffullone@progettoaroma.com>
*
    * @version  1.0 8/8/2004 (hacked)
    */
    
class Watermark
    
{
        
/**
        * Directory where the created watermarked images are stored in (for PHP access)
        * e.g. '/usr/local/apache/htdocs/images/watermark'
        */
        
var $thumbnail_dir_internal  =  'albums/watermark/';
        
/**
        * Path to watermarked directory for browser/coppermine access
        * e.g. '/images/thumbnails'
        */
        
var $thumbnail_dir_external  =  'albums/watermark/';
/**
        * Watermarked image suffix for new watermarked image
        * e.g. 'watermarksuffix_orginal.jpg'
        * WARNING: Cannot be left blank
        */
var $file_suffix 'watermark_';
        
/**
        * Error message if creation fails, this will crash the gallery for the particular image if all fails...
        */
        
var $error;
        
/**
        * where the watermark is inserted
        * topleft, bottomleft, topright, bottomright, middle, bottommiddle
        */
var $watermark_position "BOTTOMMIDDLE";
        
/**
        * the watermark filename
* currently MUST be a PNG24 file! working on gif/jpg support
        */
var $watermark_file;
        
/**
        * which kind of output is request
        * valid value is JPG, PNG*
*    * if using PNG - look @ www.skybax.com for more information on how to secure images
*      (neat transparency effect that disables 'easy' harvesting of images)
        */
var $extension 'JPG';
        
/**
* this method REQUIRES the GD 2.0+
        * @param string $imagefile Filename of source image
        */
        
function add_watermark $imagefile )
        {
if ((
is_file($this->watermark_file)) && (function_exists('imagecreatetruecolor')))
{
$this->image_name  =  $this->file_suffix.basename($imagefile);
$this->image_tag  =  $imagefile;
if (!
is_file($this->thumbnail_dir_internal $this->image_name))
{
$old $this->image_info($imagefile);

$logo ImageCreateFromPNG($this->watermark_file) or die($this->watermark_file.' is not a valid PNG24 file!');
$logo_w imagesX($logo);
$logo_h imagesY($logo);

// Check that image to be modified is larger then the watermark. (image has to be 1.01 times the size of the watermark)f
$original $this->image_info($imagefile);
$original_w imagesX($old);
$original_h imagesY($old);
if (
$original_w > ($logo_w 1.01) && $original_h > ($logo_h 1.01)){

if (
strtoupper($this->watermark_position) == "TOPLEFT")
{
$src_x 0;
$src_y 0;
}
elseif (
strtoupper($this->watermark_position) == "TOPRIGHT")
{
$src_x $this->width $logo_w;
$src_y 0;
}
elseif (
strtoupper($this->watermark_position) == "BOTTOMLEFT")
{
$src_x 0;
$src_y $this->height $logo_h;
}
elseif (
strtoupper($this->watermark_position) == "BOTTOMRIGHT")
{
$src_x $this->width $logo_w;
$src_y $this->height $logo_h;
}
elseif (
strtoupper($this->watermark_position) == "MIDDLE")
{
$src_x $this->width/$logo_w/2;
$src_y $this->height/2  $logo_h/2;
}
elseif (
strtoupper($this->watermark_position) == "BOTTOMMIDDLE")
{
$src_x $this->width/$logo_w/2;
$src_y $this->height $logo_h 80;
}
else
{
die (
'the watermark position: ' $this->watermark_position ' is non recognized! try with: TOPLEFT, BOTTOMLEFT, TOPRIGHT, BOTTOMRIGHT, MIDDLE, BOTTOMMIDDLE');
}

$new  =  imagecreatetruecolor($this->width$this->height);

ImageAlphaBlending($newtrue) or die ("Could not alpha blend");
ImageCopy($new$old0000$this->width$this->height);
ImageCopy($new$logo$src_x$src_y00$logo_w$logo_h);    

$this->save_image($new);

ImageDestroy($new);
ImageDestroy($old);
ImageDestroy($logo);
}else{ return 
$img->image_tag; }
// $img->image_tag;

}
else
{
$arr  =  getimagesize($this->thumbnail_dir_internal $this->image_name);
$this->width   =  $arr[0];
$this->height  =  $arr[1];
}
//place $this->image_tag in the SRC of <img>
$this->image_tag  =  $this->thumbnail_dir_external $this->image_name ;
}
else { die(
'Watermarking file: '$this->watermark_file.' did not work!'); }
}

/**
        * check the directory and update the class var
        */
function check_conf()
{
     if (
strlen($this->thumbnail_dir_internal)  &&  (substr($this->thumbnail_dir_internal, -1) != '/'))
            {
                
$this->thumbnail_dir_internal  .=  '/';
            }
            if (
strlen($this->thumbnail_dir_external)  &&  (substr($this->thumbnail_dir_external, -1) != '/'))
            {
                
$this->thumbnail_dir_external  .=  '/';
            }

}

        
/**
        * check the imagefile info to create the correct image stream
        * @param $imagefile the image filename
        * @return $img the image stream
        */
function image_info($imagefile)
{
$tmp_extension strtoupper(substr(basename($imagefile), -3));

if ( 
$tmp_extension == 'JPG' )
{
$img ImageCreateFromJPEG($imagefile) or die ("Could not create from JPEG");
}
elseif ( 
$tmp_extension == 'PNG' )
{
$img ImageCreateFromPNG($imagefile) or die ("Could not create from PNG");
}
else
{
die(
'the extension '.$tmp_extension.' is not valid, try with JPG or PNG images');
}

$this->width imagesX($img);
$this->height imagesY($img);
return 
$img;
}


        
/**
        * save the image to disk
        * @param $img the image stream
        * @return void
        */
function save_image($img)
{
if (
strtoupper($this->extension) == 'JPG' )
{
$this->image_name  =  substr($this->image_name0, -4) . '.jpg';
ImageJPEG($img$this->thumbnail_dir_internal $this->image_name);
}
elseif (
strtoupper($this->extension) == 'PNG' )
{
$this->image_name  =  substr($this->image_name0, -4) . '.png';
ImagePNG($img$this->thumbnail_dir_internal $this->image_name);
}
else
{
die(
'the extension '.$this->extension.' is not valid, try with JPG or PNG');
}
}
        
/**
        * delete a thumbnail or watermark file image from the thumbnail_dir_internal
        * @param $imagefile the image filename
        * @return void
        */
function delete_image($imagefile)
{
$this->image_name  =  basename($imagefile);

if (
is_file($this->thumbnail_dir_internal $this->image_name))
{
unlink($this->thumbnail_dir_internal $this->image_name);
}
else
{
die(
'file does not exist');
}
}
//end watermark class
?>
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: vexd on April 17, 2005, 06:30:21 pm
OK, It works like a charm but how do I make the watermark come up AUTOMATICALLY. I added 100's of pictures at a time, Is there a way for it to watermark all the pictures automatically because I cant go into all of them and select 'yes' that would take too long.

If so, let me know.
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: cdrake on May 01, 2005, 10:28:33 pm
I have imagemagick and gd2 on my server. I use imagemagick as the default for coppermine. If I install this mod will it work or will I need to tell coppermine to use gd2?
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: augustin on May 25, 2005, 07:09:20 am
I can't find the util.php file. I am using cpg 1.2 my gallery is working but can't find this file to change it
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: Tranz on May 25, 2005, 07:15:15 am
This mod is for 1.3, so you should upgrade to the latest, 1.3.3, in order to apply it.
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: augustin on May 26, 2005, 06:12:58 am
thanks...:) I am using cpg with phpnuke. I don't see a version of cpg of 1.3 for phpnuke. Can I Just apply 1.3 to the cpg module in phpnuke?
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: Tranz on May 26, 2005, 06:17:48 am
Unfortunately, the current cpg developers know nothing about the phpnuke/cpg code. The developers have moved on to cpgnuke.com
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: protox on June 10, 2005, 05:19:28 pm
I got a pb with the special chars of my files .. like the picture named ' irisées ' makes me this error :
Code: [Select]
Warning: imagecreatefromjpeg(albums/userpics/10025/normal_02-Iris%E9es.jpg): failed to open stream: No such file or directory in /home/www/db42903f11964a7206bcc6bf748cb626/web/include/watermark.class.php on line 176
Could not create from JPEG

** EDIT ** Solved with the urlencode function
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: Biker.ie on July 11, 2005, 03:22:21 am
I'm having the same problem (but with spaces turning into %20's instead) where exactly did you insert this 'urlencode' function into watermark.class.php ?

ps. is there a quick way to reverse this code so that all images get watermarked by default ?

Code: [Select]
return $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);

} else {
require_once "include/watermark.class.php";
$watermark_file_location = 'images/watermark.png';
$picture_location = $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);;

$img = new Watermark();
$img->watermark_file = $watermark_file_location;
    $img->add_watermark($picture_location);
return $img->image_tag;
}

Regards,
Brendan.
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: marcos on August 06, 2005, 01:23:49 pm
It is CPG 1.4 compatible ?

I'll be upgrading in a few weeks... is someone already made it...
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: sigepjedi on September 19, 2005, 05:18:23 pm
It is CPG 1.4 compatible ?

I'll be upgrading in a few weeks... is someone already made it...

I would also like this on 1.4 platform... please advise.
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: Joachim Müller on September 19, 2005, 10:43:29 pm
why don't you try to find it out and post your results? How else should we know unless someone tries, especially since cpg1.4.x goes currently unsupported. Be a giver as well instead of being only a taker.
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: sigepjedi on September 25, 2005, 03:46:14 am
why don't you try to find it out and post your results? How else should we know unless someone tries, especially since cpg1.4.x goes currently unsupported. Be a giver as well instead of being only a taker.

and, same...

try to find it out and post your results?

if i had figured it out, i assure you i would have posted.
My how 1.4 has really brought down the moral around here....
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: Tranz on September 25, 2005, 08:11:19 am
Watch your attitude, sigepjedi. You're making supporters reluctant to help you.
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: Dagon on September 26, 2005, 07:15:28 am
Hello folks.  This code takes a dump if a user uploads a file with a .jpeg extention instead of .jpg.

For some reason, it doesn't appear to be able to handle the 4 character extention.  It instead gives the error "PEG  is not valid, try with JPG or PNG images" when you try to view the gallery.

I created a real dirty workaround, but not a fix.

I changed this:
Code: [Select]
if ( $tmp_extension == 'JPG' )
To this:
Code: [Select]
if ( $tmp_extension == 'JPG' || $tmp_extension == 'PEG' )
I would be greatful if someone could actually come up with a real fix.  I don't know enough about php to even know where to start.
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: pgrzegorc on October 16, 2005, 09:46:00 am
Where is "user1 field", because I don't understand what does it mean???

How to have a few watermarks, other watermark for each user, not the same watermark for all users???
Because I have about 10 gallery person which have access to uplao files to own gallery and I would like to add watermark for each user but of course watermark for each user must be different ( one user means one watermark), How to do this ???
Should I'll create in albums/userpics folder e.g. user1, user2 etc.? or I thinking wrongly? How this works?


Pawel

I needed a simple watermarking hack to accomplish the following:

- Compatible with GD 2.0
- On the fly watermarking
- Non server intensive
- Customize expansion
- Identify individual images to watermark
- PNG input/output support

I wanted to be able to specify which images to watermark indivually within an album. I needed to also make sure that the watermark didn't swamp the main image. I also wanted a quick way to adjust the positioning of the watermark on the image.

The way this mod works is evaluates the user1 field to determine if image is to be watermarked. If 'yes' then it sends the image uri to the watermark class to be evaluated if the images is to small for watermark, if not it watermarks the file and save a copy to a determined folder. When the image is called a second time instead of creating a new file it pulls the created watermarked image and sends this back to the image display as a src. Any serious errors will stop the script and give descriptive results of the problem.

Planned future updates:
- Modify config to turn watermark on/off.
- Allow for evaluation of watermarked file date to allow for watermark updates
- Customizable setup from browser/integrate with dbase

1) First create a PNG watermark and upload it into the main images folder.

2) Ok, onto the code. *don't forget to backup all files being modified.
Open functions.inc.php and find:
Code: [Select]
return $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);
comment the code out (incase you decide to go back or the mod breaks while installing).

Add as a new line below commented code:
Code: [Select]
if ($pic_row['user1']!="YES") {

return $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);

} else {
require_once "include/watermark.class.php";
$watermark_file_location = 'images/watermark.png';
$picture_location = $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);;

$img = new Watermark();
$img->watermark_file = $watermark_file_location;
    $img->add_watermark($picture_location);
return $img->image_tag;


}

3) Create a file called watermark.class.php save this into the include folder, insert the following code and save:
Code: [Select]
<?php
    
/**
    * Custom Watermark Class for PNG or JPG watermarks with GD2
* Modified for use with Coppermine Image Gallery http://coppermine.sourceforge.net
    *
    * Usage Example:
Find in functions.inc.php:
return $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);

Replace with:
if ($pic_row['user1']!="YES") {

return $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);

} else {
require_once "include/watermark.class.php";
$watermark_file_location = 'images/watermark.png';
$picture_location = $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);;

$img = new Watermark();
$img->watermark_file = $watermark_file_location;
    $img->add_watermark($picture_location);
return $img->image_tag;


}
*
*
* @hacked   Timothy Wood <info@skybax.com>
* @Idea from SmartThumb http://www.fullo.net/progetti/smartthumb/
    * @authors to Philipp v. Criegern <criegep@criegern.com> & Francesco Fullone <ffullone@progettoaroma.com>
*
    * @version  1.0 8/8/2004 (hacked)
    */
    class Watermark
    
{
        /**
        * Directory where the created watermarked images are stored in (for PHP access)
        * e.g. '/usr/local/apache/htdocs/images/watermark'
        */
        var $thumbnail_dir_internal  =  '/home/erotic/public_html/wmarked/';
        /**
        * Path to watermarked directory for browser/coppermine access
        * e.g. '/images/thumbnails'
        */
        var $thumbnail_dir_external  =  '../wmarked/';
 /**
        * Watermarked image suffix for new watermarked image
        * e.g. 'watermarksuffix_orginal.jpg'
        * WARNING: Cannot be left blank
        */
var $file_suffix 'watermark_';
        /**
        * Error message if creation fails, this will crash the gallery for the particular image if all fails...
        */
        var $error;
        /**
        * where the watermark is inserted
        * topleft, bottomleft, topright, bottomright
        */
var $watermark_position "bottomright";
        /**
        * the watermark filename
* currently MUST be a PNG24 file! working on gif/jpg support
        */
var $watermark_file;
        /**
        * which kind of output is request
        * valid value is JPG, PNG*
*    * if using PNG - look @ www.skybax.com for more information on how to secure images 
*      (neat transparency effect that disables 'easy' harvesting of images)
        */
var $extension = 'JPG';
        /**
* this method REQUIRES the GD 2.0+
        * @param string $imagefile Filename of source image
        */
        function add_watermark $imagefile )
        {
if ((is_file($this->watermark_file)) && (function_exists('imagecreatetruecolor')))
{
$this->image_name  =  $this->file_suffix.basename($imagefile);
$this->image_tag  =  $imagefile;
if (!is_file($this->thumbnail_dir_internal $this->image_name)) 
{
$old $this->image_info($imagefile);

$logo ImageCreateFromPNG($this->watermark_file) or die($this->watermark_file.' is not a valid PNG24 file!');
$logo_w imagesX($logo); 
$logo_h imagesY($logo); 

// Check that image to be modified will not be swamped by watermark. (image has to be twice the size of the watermark)f
$original $this->image_info($imagefile);
$original_w imagesX($old); 
$original_h imagesY($old);
if ($original_w > ($logo_w 2) && $original_h > ($logo_h 2)){
if (strtoupper($this->watermark_position) == "TOPLEFT"
{
$src_x 0;
$src_y 0;

elseif (strtoupper($this->watermark_position) == "TOPRIGHT"
{
$src_x $this->width $logo_w;
$src_y 0;

elseif (strtoupper($this->watermark_position) == "BOTTOMLEFT"
{
$src_x 0;
$src_y $this->height $logo_h;

elseif (strtoupper($this->watermark_position) == "BOTTOMRIGHT"
{
$src_x $this->width $logo_w;
$src_y $this->height $logo_h;
}
else 
{
die ('the watermark position: ' $this->watermark_position ' is non recognized! try with: TOPLEFT, BOTTOMLEFT, TOPRIGHT, BOTTOMRIGHT');
}

$new  =  imagecreatetruecolor($this->width$this->height);

ImageAlphaBlending($newtrue) or die ("Could not alpha blend");
ImageCopy($new$old0000$this->width$this->height);
ImageCopy($new$logo$src_x$src_y00$logo_w$logo_h);    

$this->save_image($new);

ImageDestroy($new);
ImageDestroy($old);
ImageDestroy($logo);
}else{ return $img->image_tag; }
// $img->image_tag;

}
else
{
$arr  =  getimagesize($this->thumbnail_dir_internal $this->image_name);
$this->width   =  $arr[0];
$this->height  =  $arr[1];
}
//place $this->image_tag in the SRC of <img> 
$this->image_tag  =  $this->thumbnail_dir_external $this->image_name ;
}
else { die('Watermarking file: '$this->watermark_file.' did not work!'); }
}

 
/**
        * check the directory and update the class var
        */
function check_conf() 
{
     if (strlen($this->thumbnail_dir_internal)  &&  (substr($this->thumbnail_dir_internal, -1) != '/'))
            {
                $this->thumbnail_dir_internal  .=  '/';
            }
            if (strlen($this->thumbnail_dir_external)  &&  (substr($this->thumbnail_dir_external, -1) != '/'))
            {
                $this->thumbnail_dir_external  .=  '/';
            }

}

        /**
        * check the imagefile info to create the correct image stream
        * @param $imagefile the image filename
        * @return $img the image stream
        */
function image_info($imagefile
{
$tmp_extension strtoupper(substr(basename($imagefile), -3));

if ( $tmp_extension == 'JPG' 
{
$img ImageCreateFromJPEG($imagefile) or die ("Could not create from JPEG");
}
elseif ( $tmp_extension == 'PNG' 
{
$img ImageCreateFromPNG($imagefile) or die ("Could not create from PNG");
}
else
{
die('the extension '.$tmp_extension.' is not valid, try with JPG or PNG images');
}

$this->width imagesX($img); 
$this->height imagesY($img); 
return $img;
}


        /**
        * save the image to disk
        * @param $img the image stream
        * @return void
        */
function save_image($img
{
if (strtoupper($this->extension) == 'JPG' 
{
$this->image_name  =  substr($this->image_name0, -4) . '.jpg';
ImageJPEG($img$this->thumbnail_dir_internal $this->image_name);
}
elseif (strtoupper($this->extension) == 'PNG' 
{
$this->image_name  =  substr($this->image_name0, -4) . '.png';
ImagePNG($img$this->thumbnail_dir_internal $this->image_name);
}
else 
{
die('the extension '.$this->extension.' is not valid, try with JPG or PNG'); 
}
}
        /**
        * delete a thumbnail or watermark file image from the thumbnail_dir_internal
        * @param $imagefile the image filename
        * @return void
        */
function delete_image($imagefile
{
$this->image_name  =  basename($imagefile);

if (is_file($this->thumbnail_dir_internal $this->image_name)) 
{
unlink($this->thumbnail_dir_internal $this->image_name);
}
else
{
die('file does not exist');
}
}
//end watermark class
?>


Hope this helps -T 8)
Tested with 1.3.1

Or download the zip:
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: joeyphoto on November 05, 2005, 07:48:54 am
Cool mod but the instructions weren't very good.

I never did figure out how 'user1' is set.  So I just removed it from the script altogether
and the watermark works.
The Watermark is being applied on the fly to all images in my gallery as I view them.
The last problem I had was GD2 not being installed.  If you download the latest version of PHP,
it includes GD2 so you just need to add this line to php.ini:

Code: [Select]
extension=php_gd2.dll
These are the lines I added to functions.inc.php:
Code: [Select]
// if ($pic_row['user1']!="YES") {
//return $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. //$pic_row['filename']);
//} else {
require_once "include/watermark.class.php";
$watermark_file_location = 'images/watermark.png';
$picture_location = $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);;

$img = new Watermark();
$img->watermark_file = $watermark_file_location;
    $img->add_watermark($picture_location);
return $img->image_tag;

//}
Title: Re: Another watermark mod (simpliest available) GD2 compatiable
Post by: surjo_becarz on November 13, 2005, 10:30:19 pm
I have done every thing as instructed but it's not working it'a giving out this error Warning: imagecreatefromjpeg(albums/userpics/10018/thumb_04112005%28019%29.jpg): failed to open stream: No such file or directory in /home/bdcarzc/public_html/gallery/include/watermark.class.php on line 176
Could not create from JPEG
Title: It works!
Post by: bingnet on November 15, 2005, 10:02:47 am
 :D It worked for me!  see it in action on cpg 1.3.3 : http://gallery.tefilah.net

Difficulties:  ???
Title: Re: Watermark for ver 1.42
Post by: amirw2k on November 30, 2005, 11:44:26 am
This is very nice  :)

I'm using ver 1.42 and I had to try it for myself, so from a first look it works perfectly with a small change to the code.

The only problem with this script is that the watermarked files aren't getting deleted so it can overload the hard-disk if you don't delete them manually.

In order to install on 1.42, do the following:
1. Copy the file watermark.class.php into the include directory (all files are attached in the first message)
2. Copy the file watermark.png to the image directory
3. Create a directory under the albums directory and call it "watermark". CHMOD it to 777.
4. Now here is the change - instead of changing the file functions.inc.php as instructed, replace the following lines:

In the file include/functions.inc.php

Look for this line:
Code: [Select]
$filepathname = $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);
Replace with these lines:

 
Code: [Select]
    if ($pic_row['user1']!="YES")
      {

$filepathname =  $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);

    } else {
require_once "include/watermark.class.php";
//$watermark_file_location = 'images/watermark.png';
$watermark_file_location = 'images/watermark.png';
$picture_location = $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);;

$img = new Watermark();
$img->watermark_file = $watermark_file_location;
    $img->add_watermark($picture_location);
$filepathname = $img->image_tag;

    }

Remember that you must put the value "YES" in the field user1 in order for it to work.

I wanted it to automatically watermark all the images so I removed this condition like this:

 
Code: [Select]
   
      if (1!=1)
      //if ($pic_row['user1']!="YES")
      {

$filepathname =  $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);

    } else {
require_once "include/watermark.class.php";
//$watermark_file_location = 'images/watermark.png';
$watermark_file_location = 'images/watermark.png';
$picture_location = $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);;

$img = new Watermark();
$img->watermark_file = $watermark_file_location;
    $img->add_watermark($picture_location);
$filepathname = $img->image_tag;

    }
This way, the first line will be ignored always, and you can still go back to the original code if you wish.

Have fun and thanks for the mod,

Amir W