Advanced search  

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Pages: 1 2 [3] 4   Go Down

Author Topic: Another watermark mod (simpliest available) GD2 compatiable  (Read 75443 times)

0 Members and 1 Guest are viewing this topic.

kegobeer

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 4637
  • Beer - it does a body good!
    • The Kazebeer Family Website
Re: Another watermark mod (simpliest available) GD2 compatiable
« Reply #40 on: February 24, 2005, 06:05:25 am »

Have you reviewed all the posts in this thread?
Logged
Do not send me a private message unless I ask for one.  Make your post public so everyone can benefit.

There are no stupid questions
But there are a LOT of inquisitive idiots

tumnus

  • Coppermine newbie
  • Offline Offline
  • Posts: 12
    • http://www.thedarkbasement.com
Re: Another watermark mod (simpliest available) GD2 compatiable
« Reply #41 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?
Logged
Be kind, man. Don't be mankind.

skybax

  • VIP
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 180
    • SKYBAX Communications
Re: Another watermark mod (simpliest available) GD2 compatiable
« Reply #42 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
Logged
(http://www.skybax.com/hotImage/post_footer.gif)
Don't contact me for support over PM or email unless I requested you to do so. Instead: post on the proper board.

bangerkcknbck

  • Coppermine newbie
  • Offline Offline
  • Gender: Male
  • Posts: 7
Re: Another watermark mod (simpliest available) GD2 compatiable
« Reply #43 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
?>
Logged

vexd

  • Coppermine newbie
  • Offline Offline
  • Posts: 6
Re: Another watermark mod (simpliest available) GD2 compatiable
« Reply #44 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.
Logged

cdrake

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Gender: Male
  • Posts: 67
Re: Another watermark mod (simpliest available) GD2 compatiable
« Reply #45 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?

augustin

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 26
Re: Another watermark mod (simpliest available) GD2 compatiable
« Reply #46 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
Logged

Tranz

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Female
  • Posts: 6149
Re: Another watermark mod (simpliest available) GD2 compatiable
« Reply #47 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.
Logged

augustin

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 26
Re: Another watermark mod (simpliest available) GD2 compatiable
« Reply #48 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?
Logged

Tranz

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Female
  • Posts: 6149
Re: Another watermark mod (simpliest available) GD2 compatiable
« Reply #49 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
Logged

protox

  • Coppermine novice
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 49
  • Digital Photographer
    • x-poz
Re: Another watermark mod (simpliest available) GD2 compatiable
« Reply #50 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
« Last Edit: June 15, 2005, 11:16:19 am by protox »
Logged
Latest shot from " Les disséqueurs de société " :

(http://x-poz.org/cpmfetch/cfimageget.php?cmd=last)

Biker.ie

  • Coppermine newbie
  • Offline Offline
  • Gender: Male
  • Posts: 1
    • Irish Biker Forum
Re: Another watermark mod (simpliest available) GD2 compatiable
« Reply #51 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.

marcos

  • Coppermine novice
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 33
    • Fly By!
Re: Another watermark mod (simpliest available) GD2 compatiable
« Reply #52 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...
Logged
goingtowritethislaterbecausemyspacebarisnotworkingproperly

sigepjedi

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 111
Re: Another watermark mod (simpliest available) GD2 compatiable
« Reply #53 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.
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: Another watermark mod (simpliest available) GD2 compatiable
« Reply #54 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.
Logged

sigepjedi

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 111
Re: Another watermark mod (simpliest available) GD2 compatiable
« Reply #55 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....
Logged

Tranz

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Female
  • Posts: 6149
Re: Another watermark mod (simpliest available) GD2 compatiable
« Reply #56 on: September 25, 2005, 08:11:19 am »

Watch your attitude, sigepjedi. You're making supporters reluctant to help you.
Logged

Dagon

  • Coppermine newbie
  • Offline Offline
  • Posts: 3
Re: Another watermark mod (simpliest available) GD2 compatiable
« Reply #57 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.
Logged

pgrzegorc

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 45
Re: Another watermark mod (simpliest available) GD2 compatiable
« Reply #58 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:
Logged

joeyphoto

  • Coppermine newbie
  • Offline Offline
  • Posts: 14
Re: Another watermark mod (simpliest available) GD2 compatiable
« Reply #59 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;

//}
Logged
Pages: 1 2 [3] 4   Go Up
 

Page created in 0.037 seconds with 20 queries.