I was unable to modify my original post and I do think that the top post should be the newest version. So I suggest you either split this post off or move it to the first somehow.
I decided to "modify" this mod so it'll work in CPG 1.3 and my brother helped me fix the "_normal" bug
Permanent Watermark with GD2 MOD by Sammy
For CPG users who wants to add GD2 watermark function on their gallery.
This MOD uses GD2!
Here is how to mod CPG 1.3 to be able to add watermark automatically on new pics and by choise on all pics in selected album.
This is quite long post, but it takes only about 10 minutes to add this mod
Files that needs to be modified:
Lang/english.php
include/picmgmt.inc.php
util.php
config.php
(and 4 SQL command to execute)
REMEMBER to take backup from all files that You are modifying
1.
Open file Lang/english.php
Find this:'th_wd' => 'Width',
Add this after it
'wm_bottomright' => 'Bottom right',
'wm_bottomleft' => 'Bottom left',
'wm_topleftt' => 'Up left',
'wm_topright' => 'Up Right',
'wm_both' => 'Both',
'wm_original' => 'Original',
'wm_resized' => 'Resized',
Find this:
array('Display notices in debug mode', 'debug_notice', 1), //cpg1.3.0
Add this after it
'Image watermarking',
array('Watermark Image on upload', 'enable_watermark', 1),
array('Where to place the watermark', 'where_put_watermark', 11),
array('which files to watermark', 'which_files_to_watermark', 12),
array('Which file to use for watermark', 'watermark_file', 0),
Find this: 'delete_orphans' => 'Delete orphaned comments (works on all albums)',
Add this a line after it 'watermarks' => 'Add watermarks',
'watermark_normal' => 'Resized images only',
'watermark_image' => 'Original sized only',
'watermark_both' => 'Original and resized images',
'watermark_wait' => 'Watermarking images...',
'watermark_continue_wait' => 'Continuing to watermarking originals and/or resized images...',
2.
Open file include/picmgmt.inc.php
Find this:$image_filesize = filesize($image);
Add this before it //Adds watermarks to new images
if ($CONFIG['enable_watermark'] == '1' && $CONFIG['which_files_to_watermark'] == 'both' || $CONFIG['which_files_to_watermark'] == 'original') {
if (!watermark($image)) //this is for full size image
return false;
}
if ($CONFIG['enable_watermark'] == '1' && $CONFIG['which_files_to_watermark'] == 'both' || $CONFIG['which_files_to_watermark'] == 'resized') {
if (file_exists($normal) && !watermark($normal)) //this is for intermediate size image
return false;
}
The following line has been modified to fix the the "_normal bug"
if (file_exists($normal) && !watermark($normal)) //this is for intermediate size image
Find this:?>
(or end of picmgmt.inc.php)
Add this before it /**
* watermark_image()
*
* Create a file containing a watermarked image
*
* @param $src_file the source file
* @param $dest_file the destination file
* @param $new_size the size of the square within which the new image must fit
* @param $method the method used for image resizing //ainoastaan gd2
* @return 'true' in case of success
*/
function watermark($src_file)
{
global $CONFIG, $ERROR;
global $lang_errors;
$imginfo = getimagesize($src_file);
if ($imginfo == null)
return false;
// GD can only handle JPG & PNG images
if ($imginfo[2] != GIS_JPG && $imginfo[2] != GIS_PNG) {
$ERROR = $lang_errors['gd_file_type_err'];
return false;
}
// height/width
$srcWidth = $imginfo[0];
$srcHeight = $imginfo[1];
/* if ($thumb_use == 'ht') {
$ratio = $srcHeight / $new_size;
} elseif ($thumb_use == 'wd') {
$ratio = $srcWidth / $new_size;
} else {
$ratio = max($srcWidth, $srcHeight) / $new_size;
}
$ratio = max($ratio, 1.0);*/
$destWidth = $srcWidth; //(int)($srcWidth / $ratio);
$destHeight = $srcHeight; //(int)($srcHeight / $ratio);
$dest_file = $src_file;
// Method for thumbnails creation
// switch ($method) {
// case "gd2" :
if (!function_exists('imagecreatefromjpeg')) {
cpg_die(CRITICAL_ERROR, 'PHP running on your server does not support the GD image library, check with your webhost if ImageMagick is installed', __FILE__, __LINE__);
}
if (!function_exists('imagecreatetruecolor')) {
cpg_die(CRITICAL_ERROR, 'PHP running on your server does not support GD version 2.x, please switch to GD version 1.x on the config page', __FILE__, __LINE__);
}
if ($imginfo[2] == GIS_JPG)
$src_img = imagecreatefromjpeg($src_file);
else
$src_img = imagecreatefrompng($src_file);
if (!$src_img) {
$ERROR = $lang_errors['invalid_image'];
return false;
} //duunataan wesileima
$dst_img = imagecreatetruecolor($destWidth, $destHeight);
/*$dst_img =*/ ImageAlphaBlending($dst_img, true) or die ("Could not alpha blend"); // Enable when on GD 2+
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $destWidth, (int)$destHeight, $srcWidth, $srcHeight);
$logoImage = ImageCreateFromPNG($CONFIG['watermark_file']);
$logoW = ImageSX($logoImage);
$logoH = ImageSY($logoImage);
//where is the watermark displayed...
$pos = $CONFIG['where_put_watermark'];
if ($pos == "topleft") {
$src_x = 5;
$src_y = 5;
} else if ($pos == "topright") {
$src_x = $srcWidth - ($logoW + 5);
$src_y = 5;
} else if ($pos == "bottomleft") {
$src_x = 5;
$src_y = $srcHeight - ($logoH + 5);
} else if ($pos == "bottomright") {
$src_x = $srcWidth - ($logoW + 5);
$src_y = $srcHeight - ($logoH + 5);
}
ImageCopy($dst_img,$logoImage,$src_x,$src_y,0,0,$logoW,$logoH); //$dst_x,$dst_y,0,0,$logoW,$logoH);
imagejpeg($dst_img, $src_file, $CONFIG['jpeg_qual']);
imagedestroy($src_img);
imagedestroy($dst_img);
// break;
//}
// Set mode of uploaded picture
// We check that the image is valid
$imginfo = getimagesize($src_file);
if ($imginfo == null) {
$ERROR = $lang_errors['resize_failed'];
@unlink($src_file);
return false;
} else {
return true;
}
}