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 75440 times)

0 Members and 1 Guest are viewing this topic.

skybax

  • VIP
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 180
    • SKYBAX Communications
Another watermark mod (simpliest available) GD2 compatiable
« 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:
« Last Edit: August 25, 2004, 08:50:18 pm by GauGau »
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.

Tarique Sani

  • VIP
  • Coppermine addict
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 2712
    • http://tariquesani.net
Re: [MOD] Another watermark mod (simpliest available) GD2 compatiable
« Reply #1 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
Logged
SANIsoft PHP applications for E Biz

kegobeer

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 4637
  • Beer - it does a body good!
    • The Kazebeer Family Website
Re: [MOD] Another watermark mod (simpliest available) GD2 compatiable
« Reply #2 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.
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

skybax

  • VIP
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 180
    • SKYBAX Communications
Re: [CPG1.3.x]: Another watermark mod (simpliest available) GD2 compatiable
« Reply #3 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.
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.

r00t

  • Coppermine newbie
  • Offline Offline
  • Posts: 5
    • http://www.ForgetTheFilm.com
Re: [CPG1.3.x]: Another watermark mod (simpliest available) GD2 compatiable
« Reply #4 on: August 15, 2004, 09:51:30 pm »

i can give you access to a server with imagemagick if you want
Logged

skybax

  • VIP
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 180
    • SKYBAX Communications
Re: [CPG1.3.x]: Another watermark mod (simpliest available) GD2 compatiable
« Reply #5 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.

« Last Edit: August 21, 2004, 03:25:51 am by skybax »
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.

Mario1

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 28
Re: [CPG1.3.x]: Another watermark mod (simpliest available) GD2 compatiable
« Reply #6 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?
Logged

skybax

  • VIP
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 180
    • SKYBAX Communications
Re: [CPG1.3.x]: Another watermark mod (simpliest available) GD2 compatiable
« Reply #7 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
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.

Mario1

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 28
Re: [CPG1.3.x]: Another watermark mod (simpliest available) GD2 compatiable
« Reply #8 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?
« Last Edit: December 15, 2004, 06:05:53 pm by Mario1 »
Logged

Joachim Müller

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

skybax

  • VIP
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 180
    • SKYBAX Communications
Re: [CPG1.3.x]: Another watermark mod (simpliest available) GD2 compatiable
« Reply #10 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.
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.

crashnet

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 69
Re: Another watermark mod (simpliest available) GD2 compatiable
« Reply #11 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.

erroneus

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 58
Re: Another watermark mod (simpliest available) GD2 compatiable
« Reply #12 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.
« Last Edit: September 02, 2004, 01:42:51 pm by erroneus »
Logged

skybax

  • VIP
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 180
    • SKYBAX Communications
Re: Another watermark mod (simpliest available) GD2 compatiable
« Reply #13 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"
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.

crashnet

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 69
Re: Another watermark mod (simpliest available) GD2 compatiable
« Reply #14 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.

erroneus

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

squish

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

squish

  • Coppermine newbie
  • Offline Offline
  • Posts: 4
Re: Another watermark mod (simpliest available) GD2 compatiable
« Reply #18 on: September 06, 2004, 06:04:35 am »

Here is the code, I"ve pasted from  lines  1778 to 1785

Code: [Select]
return $return;
}





?>


Logged

Casper

  • VIP
  • Coppermine addict
  • ***
  • Country: 00
  • Offline Offline
  • Gender: Male
  • Posts: 5231
Re: Another watermark mod (simpliest available) GD2 compatiable
« Reply #19 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;


}
Logged
It has been a long time now since I did my little bit here, and have done no coding or any other such stuff since. I'm back to being a noob here
Pages: [1] 2 3 4   Go Up
 

Page created in 0.039 seconds with 19 queries.