Hello!
I used this mod and added an ability to choose between image watermark and a simple text watermark.
Text watermark may contain username and look like that, for example
www.somesite.com/username/This instruction is only valid if you have applied this mod before (cause it's not the full instruction).
In your lang file add this to Watermark section:
array('Use text watermark instead of image', 'watermark_use_text', 1),
array('Text to use for a watermark', 'watermark_text_pattern', 0),
array('Watermark text color (r,g,b)', 'watermark_text_color', 0),
array('Watermark text font size (points)', 'watermark_text_size', 0),
run this in phpMyAdmin or similar:
INSERT INTO `cpg132_config` VALUES ('watermark_text_pattern', 'test string');
INSERT INTO `cpg132_config` VALUES ('watermark_use_text', '0');
INSERT INTO `cpg132_config` VALUES ('watermark_text_color', '255,255,255');
INSERT INTO `cpg132_config` VALUES ('watermark_text_size', '10');
edit picmgmt.php , find
function watermark($src_file)
and replace
the whole function (not just that line) with this:
function watermark($src_file) {
global $CONFIG, $ERROR, $USER_DATA;
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];
$destWidth = $srcWidth; //(int)($srcWidth / $ratio);
$destHeight = $srcHeight; //(int)($srcHeight / $ratio);
$dest_file = $src_file;
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;
}
$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);
//where is the watermark displayed...
$pos = $CONFIG['where_put_watermark'];
if (!$CONFIG['watermark_use_text']) // if we are using image as a watermark
{
$logoImage = ImageCreateFromPNG($CONFIG['watermark_file']);
$logoW = ImageSX($logoImage);
$logoH = ImageSY($logoImage);
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);
}
else // using text as watermark
{
if ($pos == "topleft")
{
$src_x = 5;
$src_y = 10;
}
else if ($pos == "topright")
{
$src_x = $srcWidth - 100;
$src_y = 10;
}
else if ($pos == "bottomleft")
{
$src_x = 5;
$src_y = $srcHeight - 5;
}
else if ($pos == "bottomright")
{
$src_x = $srcWidth - 100;
$src_y = $srcHeight - 5;
}
$color_arr = explode(',',$CONFIG['watermark_text_color']);
$color = imagecolorallocate($dst_img, $color_arr[0], $color_arr[1], $color_arr[2]);
$wat_text = eval("return (\"$CONFIG[watermark_text_pattern]\");");
imagettftext($dst_img,$CONFIG['watermark_text_size'],0,$src_x,$src_y,$color,'path/to/your/font/arial.ttf', $wat_text) or die ('Error - could not add a text watermark!');
}
imagejpeg($dst_img, $src_file, $CONFIG['jpeg_qual']);
imagedestroy($src_img);
imagedestroy($dst_img);
// 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;
}
}
Where "path/to/your/font/" is an absolute path to .ttf file on your server.
Now go to the config page and switch the option "use text watermark instead of image".
With this modification you are able to use such string in the "watermark text" field
www.$_SERVER[HTTP_HOST]/$USER_DATA[user_name]/
and the watermark text will be something like
www.somesite.com/username/
where username is the name of the pic's uploader. You can use other global variables as well.
It may be not safe, because it uses eval() function, so, don't use it if you are not the only one admin of the gallery.
To avoid eval() the string can be hardcoded to the script, or you can delete eval() if you are not going to use variables in your watermark.
If you place text watermark on the right side of an image - correct the line
else if ($pos == "topright")
{
$src_x = $srcWidth - 100;
$src_y = 10;
}
and change 100 to your suitable number, depending of your text length (and font size). But it's more convenient to place variable-length text watermark on the left side of an image.
Again - it uses eval() and has no validation of values you enter in config page - use it at your own risk (or modify to be more safe

)
Hope I didn't forget anything!
PS: found a typo(?) - in original code "topleft" is called "topleftt" (double "t") in lang and config files..