Hopefully this is in the right place. gaugau suggested I post this in a thread so here goes. I am starting this off by saying this is bits and pieces of code from different hacks for watermarking with my add on for deciding which images get it and which do not.
First I made my watermark image and uploaded it to my main gallery directory. My file was called watermark.png
Then I created a file called logo.php and uploaded it to the main gallery directory with the following code
<?
//Most coding by semisphere
//http://gallery.menalto.com/index.php?name=PNphpBB2&file=viewtopic&t=4053&start=0
// A few lines by BY DJ AXION
// e-mail: DJ@the-expansion.com
// Enjoy this script!
######################################################################################################
## YOUR settings HERE
######################################################################################################
// watermark IMAGE settings
$watermark_width = 143; // watermark wanted width
$watermark_height = 20; // watermark wanted height
/*
NOTE
If the watermark is resized, transparency may contain lines and spots of your transparency color.
Try to put the right size from the beginning
*/
$opacity = 90; // 0 completely invisible
$margin_x = 0.1; // margin from the right in pixels (x axis)
$margin_y = 0.1; // margin from the bottom in pixels (y axis)
$quality = 100; // 100 is maximum quality
$watermark_image = "watermark.png";
// Full path to image
$watermark_type = "PNG"; // JPEG or PNG
$transColor = array(0, 0, 0); // transparency color index in rgb
######################################################################################################
## DON'T EDIT BELLOW THIS LINE
## well, if you want to, you won't be busted ;-)
######################################################################################################
// get the file we want to watermark
$file = imagecreatefromjpeg($picturename);
// get the image details and create an image
$image_width = imagesx($file);
$image_height = imagesy($file);
$image = $file;
if (!preg_match("/thumb_/i", "$picturename"))
{
// get the watermark details, and open it
$watermark_info = getImageSize($watermark_image);
eval ("\$watermark = ImageCreateFrom$watermark_type(\$watermark_image);");
// calculate scale of watermark and create scaled watermark
$scaled_watermark = imageCreateTrueColor($watermark_width, $watermark_height);
// resize the watermark to the new scale
imageCopyResampled($scaled_watermark, $watermark, 0, 0, 0, 0, $watermark_width, $watermark_height, $watermark_info[0], $watermark_info[1]);
// set the transparent color ($transColor)
$transparentColor = imagecolorallocate ($scaled_watermark, $transColor[0],$transColor[1],$transColor[2]);
imagecolortransparent($scaled_watermark, $transparentColor);
// add the watermark to the image
ImageCopyMerge($image, $scaled_watermark, $image_width - $watermark_width - ($watermark_width * $margin_x), $image_height - $watermark_height - ($watermark_height * $margin_y), 0, 0, $watermark_info[0], $watermark_info[1], $opacity);
}
// send out a header
header("content-type:image/jpeg");
// send the image
imagejpeg($image,'',$quality);
// clean up
imagedestroy($image);
?>
Next in include/functions.inc.php find
return $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);
and change it to
if ($pic_row['user1']!="YES") {
return $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);
} else {
return 'logo.php?picturename='.$url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']); }
In the config section of your gallery set the "Custom fields for image description" Field 1 name to "Watermark".
Now is the optional part. If you want the watermark on by default (it is only on by default for images you upload after you make this change, the other images you will have to go through and turn it on one by one. I haven't found a way around that although I am sure there is a way to do it in one big batch) go to
include/picmgmt.inc.php and change
function add_picture($aid, $filepath, $filename, $title = '', $caption = '', $keywords = '', $user1 = '', $user2 = '', $user3 = '', $user4 = '', $category = 0, $raw_ip = '', $hdr_ip = '')
to
function add_picture($aid, $filepath, $filename, $title = '', $caption = '', $keywords = '', $user1 = 'YES', $user2 = '', $user3 = '', $user4 = '', $category = 0, $raw_ip = '', $hdr_ip = '')
The script looks for the "YES" in the watermark field ($user1) so you can basically set it to anything other than YES and the watermark won't appear.
I am sure this hack is pretty primitive so if anyone has a way to improve it, feel free.
![Smiley :)](https://forum.coppermine-gallery.net/Smileys/default/smiley.gif)
I hope someone finds this useful.
![Smiley :)](https://forum.coppermine-gallery.net/Smileys/default/smiley.gif)
BTW: If you want to see it in action go to
http://www.baileychase.com/Gallery/ most of the images have the watermark on check
http://www.baileychase.com/Gallery/thumbnails.php?album=173 for a few that do not.
EDITED: Updated watermarking code to include the change Frank suggested for determining a thumbnail on page 3 of this thread