Permanent Watermark with GD2 - Page 5 Permanent Watermark with GD2 - Page 5
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

Permanent Watermark with GD2

Started by Burpee, June 20, 2004, 11:43:25 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Hein Traag

Right i applied all code changes, without wrecking the cpg (hooray for me) and now i wanted to apply the watermarking to
some albums as per test.

Went to Admin Tools and selected Add Watermarking, choosing both resized and original pictures.
Selected the album to apply the watermarking to and hit Submit. After some thinking on the serverside is displays a page which says all pics were update succesfully.

All ok so far.

Except for one thing. I don't see the watermarking appear on any of the pictures. I tried setting the intermediate picture size to a lower size, following the advice Sammy gave but with no result. The path to the images is in order, goes from /public_html/ all the way to logo.png so that should not be the problem.

Anybody got an idea where i might look for the answer ?

Thanks
Hein

Tranz

Did you go through the error logs to make sure that the file path is interpreted correctly?

Hein Traag

#82
*removed debug list

If i read the whole thread correctly this should also work on pics that were already uploaded.

Has to be something to do with the path to logo.png

In a nutshell: Admin Tools - Add Watermarking (choose resized and normal) - choose album - hit Submit
That should add watermarking to a album that already was in the gallery right ?
Assuming the path to the images was correct in both config and mysql.

Tried it by uploading a picture thru upload.php.. again no result.

Past my bedtime and lack of coffee.. If someone can point me in the right direction its appreciated. For now it's bye bye  ;)

Tranz

It should work on existing photos.

(This is when it is difficult to help people with different webhosts. )

For example, my full path to the .png is:
/home/username/public_html/galleryname/blahblah

If you're unsure of the absolute path, you should ask your host.

Hein Traag

Thanks TranzNDance that did it. Forgot to type full path  :o.

I did find a other option to add watermarking to pictures. I did some testing with WebDrive (http://www.webdrive.com/) which connects a ftp folder as a normal folder under Windows.
And then I used FastStone resizer/renamer to add watermarking. One drawback to some maybe that you need a decent internet connection.

Thanks for the help!

peezy

Ok, i've tried to re-install this mod like 5 times from scratch and have been working on it for a while and keep getting an error.

Warning: imagecreatefrompng(/your/full/path/to/logo.png): failed to open stream: No such file or directory in /home/club303/public_html/fp-photo/include/picmgmt.inc.php on line 303

Warning: imagesx(): supplied argument is not a valid Image resource in /home/club303/public_html/fp-photo/include/picmgmt.inc.php on line 304

Warning: imagesy(): supplied argument is not a valid Image resource in /home/club303/public_html/fp-photo/include/picmgmt.inc.php on line 305

Warning: imagecopy(): supplied argument is not a valid Image resource in /home/club303/public_html/fp-photo/include/picmgmt.inc.php on line 325
albums/userpics/10001/photocart.jpg updated succesfully!


Can anybody help me? anyone know where this problem might be?

Tranz

In Config, did you put the full path to the watermark file?

If this was in the actual error message (and you hadn't edited it when posting), then it is incorrect:
/your/full/path/to/logo.png

You can get the full path info in the rest of the error message which shows where the files are located.

peezy

nope, that didn't work either now it says

Watermarking images...

Warning: imagecreatefrompng(/home/club303/public_html/fp/watermark.png): failed to open stream: No such file or directory in /home/club303/public_html/fp-photo/include/picmgmt.inc.php on line 303

Warning: imagesx(): supplied argument is not a valid Image resource in /home/club303/public_html/fp-photo/include/picmgmt.inc.php on line 304

Warning: imagesy(): supplied argument is not a valid Image resource in /home/club303/public_html/fp-photo/include/picmgmt.inc.php on line 305

Warning: imagecopy(): supplied argument is not a valid Image resource in /home/club303/public_html/fp-photo/include/picmgmt.inc.php on line 325
albums/userpics/10001/photocart.jpg updated succesfully!


it says that for each picture in the album

Tranz

Is this correct:
/home/club303/public_html/fp/watermark.png

The rest of the error message say your files are in
/home/club303/public_html/fp-photo/

If you try to access the watermark file via browser, does it work? So you should be able to see it http://yourdomain.tld/fp/watermark.png if
/home/club303/public_html/fp/watermark.png
is correct.

peezy

aww man.... the file was kinda right, i didn't realize photoshop saved it watermark.PNG not watermark.png 

i hate it when it's case sensative!

Thanks for the help!

RGSMDNR

im getting this error...

Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 2412 bytes) in /home/virtual/site430/fst/var/www/html/coppermine/include/picmgmt.inc.php on line 226

it worked once (kinda, the watermark was fuzzy) but now i get that..

thoughts?

Joachim Müller


RGSMDNR

ok, well it looks like ill have to live with it for now and get my users to upload non hi res pics.

now where in the code does it say how big the watermark image can be? is there a limit?

also on smaller pics, will it resize the watermark to fit?

partypics

#93
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..

gab696

I have tried to install this Hack but when i try to change the watermarking in the config pannel.
The changes are not saved.  ???
I'am not sure to have correctly inserted the 4 lines in my base and the config.php (i'am a newbie  :-\\ )


partypics

This will work only if you have correctly applied the first part - image watermark. Try phpMyAdmin to insert sql statements.

biootik

hi all !

i've just installed "permanent Watermaking" on my 1.3.0 coppermine site ..

it works well by upload and by the util page too , but only on resized pics, on original pics it doesn't work at all .
well, it says that pics have been watermarked , but they are not.

any of u got this matter ?  ??? ??? ???

ps:i supposed it was my code copy which was bad  , but i've checked 3 times the code , and i did it well .

tks for answering..

bioo

romans815

Am looking for any and all advise. I added everything and get this:

>>>>>>>>>>>>>>>>>>>>>>>>IN THE UPLOAD AND ASSIGN TO ALBUM SECTION

Warning: imagecreatefrompng(home/champ1/public_html/gallery/images/watermark.png): failed to open stream: No such file or directory in /home/champ1/public_html/gallery/include/picmgmt.inc.php on line 304

Warning: imagesx(): supplied argument is not a valid Image resource in /home/champ1/public_html/gallery/include/picmgmt.inc.php on line 305

Warning: imagesy(): supplied argument is not a valid Image resource in /home/champ1/public_html/gallery/include/picmgmt.inc.php on line 306

Warning: imagecopy(): supplied argument is not a valid Image resource in /home/champ1/public_html/gallery/include/picmgmt.inc.php on line 323

Warning: imagecreatefrompng(home/champ1/public_html/gallery/images/watermark.png): failed to open stream: No such file or directory in /home/champ1/public_html/gallery/include/picmgmt.inc.php on line 304

Warning: imagesx(): supplied argument is not a valid Image resource in /home/champ1/public_html/gallery/include/picmgmt.inc.php on line 305

Warning: imagesy(): supplied argument is not a valid Image resource in /home/champ1/public_html/gallery/include/picmgmt.inc.php on line 306

Warning: imagecopy(): supplied argument is not a valid Image resource in /home/champ1/public_html/gallery/include/picmgmt.inc.php on line 323


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>IN THE ADMIN SECTION

Watermarking images...

Warning: imagecreatefrompng(home/champ1/public_html/gallery/images/watermark.png): failed to open stream: No such file or directory in /home/champ1/public_html/gallery/include/picmgmt.inc.php on line 304

Warning: imagesx(): supplied argument is not a valid Image resource in /home/champ1/public_html/gallery/include/picmgmt.inc.php on line 305

Warning: imagesy(): supplied argument is not a valid Image resource in /home/champ1/public_html/gallery/include/picmgmt.inc.php on line 306

Warning: imagecopy(): supplied argument is not a valid Image resource in /home/champ1/public_html/gallery/include/picmgmt.inc.php on line 323
albums/userpics/10001/normal_DSC00988.jpg updated succesfully!

PBas

Well.... i've aplied the watermarking mod and it works perfectly. (had one error ... path ... but that was my problem, not the MOD)

The question:
Is it possible to have a smaller watermark pic for normal size pics? or working with %... i don't know.


Thanks!

(coppermine gallery since v1.2 - 1 year long - now updated to 1.3.2)

bibendum

Hi

Thanks for this wonderfull mod.

Is it possible to select wich pictures you want to apply Watermark with admin/utils ?

Because some of my pictures are copyrighted by their owrners and i don't want to apply my copyright !!!!

Even with pictures to be validated by admin, select yes/no to apply Watermark.

Thanks a lot