Watermark on a per image basis - Page 3 Watermark on a per image basis - Page 3
 

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

Watermark on a per image basis

Started by Karri, January 22, 2004, 02:15:46 AM

Previous topic - Next topic

0 Members and 3 Guests are viewing this topic.

Spiderm@n(tm)

#40
I have made some edits in the code.
It now works with JPEG and PNG images, detects the type and the size of the watermark image automaticaly.

<?php
function get_ext($fname)
{
$arr explode(".",$fname);
return $arr[sizeof($arr)-1];
}

function 
wm_pos ($img_size$wm_size$margin$pos)
{
switch ($pos)
{
case 0$rpos $margin; break;
case 1$rpos $img_size/$wm_size/2; break;
case 2$rpos $img_size $margin $wm_size; break;
default: $rpos $img_size $margin $wm_size; break;
}
return $rpos;
}

//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

/*
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

*/

$position = array(22); // position of the watermark image (x, y)
// 0,0 | 0,1 | 0,2
// 1,0 | 1,1 | 1,2
// 2,0 | 2,1 | 2,2

$opacity 80; // 0 completely invisible

$margin_x 10; // margin from the right in pixels (x axis)

$margin_y 10; // margin from the bottom in pixels (y axis)

$quality 100; // 100 is maximum quality

$watermark_image "watermark.jpg"; // Full path to image 

$transColor = array(000); // transparency color index in rgb

######################################################################################################
## DON'T EDIT BELLOW THIS LINE
## well, if you want to, you won't be busted
######################################################################################################

if (get_ext($watermark_image) == ('jpg' || 'jpeg'))
$watermark_type "JPEG"; // JPEG
if (get_ext($watermark_image) == 'png')
$watermark_type "PNG"; // PNG

// get the file we want to watermark
$get $_GET["picturename"];
if (get_ext($get) == ('jpg' || 'jpeg'))
$image_type JPEG;
if (get_ext($get) == 'png')
$image_type PNG;

eval ("\$file = ImageCreateFrom$image_type(\$get);");

// get the image details and create an image
$image_width imagesx($file);
$image_height imagesy($file);
$image $file;







//if ((!preg_match("/thumb_/i", "$picturename")) && ($image_width > 250))
if ($image_width 250)
{

// get the watermark details, and open it
$watermark_info getImageSize($watermark_image);

eval ("\$watermark = ImageCreateFrom$watermark_type(\$watermark_image);");
$watermark_width imagesx($watermark);
$watermark_height imagesy($watermark);

// 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$watermark0000$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, wm_pos($image_width, $watermark_width, $margin_x, 0), wm_pos($image_height, $watermark_height, $margin_y, 0), 0, 0, $watermark_info[0], $watermark_info[1], $opacity); //Upper Left
// ImageCopyMerge($image, $scaled_watermark, wm_pos($image_width, $watermark_width, $margin_x, 0), wm_pos($image_height, $watermark_height, $margin_y, 1), 0, 0, $watermark_info[0], $watermark_info[1], $opacity); //Upper Center
// ImageCopyMerge($image, $scaled_watermark, wm_pos($image_width, $watermark_width, $margin_x, 0), wm_pos($image_height, $watermark_height, $margin_y, 2), 0, 0, $watermark_info[0], $watermark_info[1], $opacity); //Upper Right
// ImageCopyMerge($image, $scaled_watermark, wm_pos($image_width, $watermark_width, $margin_x, 1), wm_pos($image_height, $watermark_height, $margin_y, 0), 0, 0, $watermark_info[0], $watermark_info[1], $opacity); //Center Left
// ImageCopyMerge($image, $scaled_watermark, wm_pos($image_width, $watermark_width, $margin_x, 1), wm_pos($image_height, $watermark_height, $margin_y, 1), 0, 0, $watermark_info[0], $watermark_info[1], $opacity); //Center Center
// ImageCopyMerge($image, $scaled_watermark, wm_pos($image_width, $watermark_width, $margin_x, 1), wm_pos($image_height, $watermark_height, $margin_y, 2), 0, 0, $watermark_info[0], $watermark_info[1], $opacity); //Center Right
// ImageCopyMerge($image, $scaled_watermark, wm_pos($image_width, $watermark_width, $margin_x, 2), wm_pos($image_height, $watermark_height, $margin_y, 0), 0, 0, $watermark_info[0], $watermark_info[1], $opacity); //Lower Left
// ImageCopyMerge($image, $scaled_watermark, wm_pos($image_width, $watermark_width, $margin_x, 2), wm_pos($image_height, $watermark_height, $margin_y, 1), 0, 0, $watermark_info[0], $watermark_info[1], $opacity); //Lower Center
// ImageCopyMerge($image, $scaled_watermark, wm_pos($image_width, $watermark_width, $margin_x, 2), wm_pos($image_height, $watermark_height, $margin_y, 2), 0, 0, $watermark_info[0], $watermark_info[1], $opacity); //Lower Right

ImageCopyMerge($image, $scaled_watermark, wm_pos($image_width$watermark_width$margin_x$position[0]), wm_pos($image_height$watermark_height$margin_y$position[1]), 0, 0, $watermark_info[0], $watermark_info[1], $opacity); //Using the "wm_pos" function & "position" array

}





// send out a header
header("content-type:image/$image_type");

// send the image
eval ("image$image_type (\$image,'',\$quality);");

// clean up
imagedestroy($image);

?>


The opacy works onli when the watermark image is a PNG file.
(https://coppermine-gallery.com/forum/proxy.php?request=http%3A%2F%2Fwww.danasoft.com%2Fsig%2FFeredzhanov.jpg&hash=301c2542bbd14d4700cb5f2723189d886c069528)

Karri

It should have already worked with PNG or JPG.  It didn't autodetect the type but when you were putting in the name of the watermark image, the very next line was for telling it what type of file it was.

$watermark_image        = "watermark.png";                               // Full path to image
       
       $watermark_type                = "PNG";                                 // JPEG or PNG
Thanks,
Karri

Spiderm@n(tm)

I've got some more edits:

<?php
function get_ext($fname)
{
$arr explode(".",$fname);
return $arr[sizeof($arr)-1];
}

function 
wm_pos ($img_size$wm_size$margin$pos)
{
switch ($pos)
{
case 0$rpos $margin; break;
case 1$rpos $img_size/$wm_size/2; break;
case 2$rpos $img_size $margin $wm_size; break;
default: $rpos $img_size $margin $wm_size; break;
}
return $rpos;
}

//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

/*
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

*/

$position = array(22); // position of the watermark image (x, y)
// 0,0 | 0,1 | 0,2
// 1,0 | 1,1 | 1,2
// 2,0 | 2,1 | 2,2

$opacity 80; // 0 completely invisible

$margin_x 10; // margin from the right in pixels (x axis)

$margin_y 10; // margin from the bottom in pixels (y axis)

$quality 100; // 100 is maximum quality

$watermark_image "watermark.jpg"; // Full path to image 

$transColor = array(000); // transparency color index in rgb

######################################################################################################
## DON'T EDIT BELLOW THIS LINE
## well, if you want to, you won't be busted
######################################################################################################

if (get_ext($watermark_image) == ('jpg' || 'jpeg'))
$watermark_type "JPEG"; // JPEG
if (get_ext($watermark_image) == 'png')
$watermark_type "PNG"; // PNG

// get the file we want to watermark
$get $_GET["picturename"];
if (get_ext($get) == ('jpg' || 'jpeg'))
$image_type JPEG;
if (get_ext($get) == 'png')
$image_type PNG;

eval ("\$file = ImageCreateFrom$image_type(\$get);");

// get the image details and create an image
$image_width imagesx($file);
$image_height imagesy($file);
$image $file;







//if ((!preg_match("/thumb_/i", "$picturename")) && ($image_width > 250))
if ($image_width 250)
{

// get the watermark details, and open it
$watermark_info getImageSize($watermark_image);

eval ("\$watermark = ImageCreateFrom$watermark_type(\$watermark_image);");
$watermark_width imagesx($watermark);
$watermark_height imagesy($watermark);

// set the transparent color ($transColor)
$transparentColor imagecolorallocate ($watermark$transColor[0], $transColor[1], $transColor[2]);

imagecolortransparent($watermark$transparentColor);

// add the watermark to the image
// ImageCopyMerge($image, $watermark, wm_pos($image_width, $watermark_width, $margin_x, 0), wm_pos($image_height, $watermark_height, $margin_y, 0), 0, 0, $watermark_info[0], $watermark_info[1], $opacity); //Upper Left
// ImageCopyMerge($image, $watermark, wm_pos($image_width, $watermark_width, $margin_x, 0), wm_pos($image_height, $watermark_height, $margin_y, 1), 0, 0, $watermark_info[0], $watermark_info[1], $opacity); //Upper Center
// ImageCopyMerge($image, $watermark, wm_pos($image_width, $watermark_width, $margin_x, 0), wm_pos($image_height, $watermark_height, $margin_y, 2), 0, 0, $watermark_info[0], $watermark_info[1], $opacity); //Upper Right
// ImageCopyMerge($image, $watermark, wm_pos($image_width, $watermark_width, $margin_x, 1), wm_pos($image_height, $watermark_height, $margin_y, 0), 0, 0, $watermark_info[0], $watermark_info[1], $opacity); //Center Left
// ImageCopyMerge($image, $watermark, wm_pos($image_width, $watermark_width, $margin_x, 1), wm_pos($image_height, $watermark_height, $margin_y, 1), 0, 0, $watermark_info[0], $watermark_info[1], $opacity); //Center Center
// ImageCopyMerge($image, $watermark, wm_pos($image_width, $watermark_width, $margin_x, 1), wm_pos($image_height, $watermark_height, $margin_y, 2), 0, 0, $watermark_info[0], $watermark_info[1], $opacity); //Center Right
// ImageCopyMerge($image, $watermark, wm_pos($image_width, $watermark_width, $margin_x, 2), wm_pos($image_height, $watermark_height, $margin_y, 0), 0, 0, $watermark_info[0], $watermark_info[1], $opacity); //Lower Left
// ImageCopyMerge($image, $watermark, wm_pos($image_width, $watermark_width, $margin_x, 2), wm_pos($image_height, $watermark_height, $margin_y, 1), 0, 0, $watermark_info[0], $watermark_info[1], $opacity); //Lower Center
// ImageCopyMerge($image, $watermark, wm_pos($image_width, $watermark_width, $margin_x, 2), wm_pos($image_height, $watermark_height, $margin_y, 2), 0, 0, $watermark_info[0], $watermark_info[1], $opacity); //Lower Right

ImageCopyMerge($image, $watermark, wm_pos($image_width$watermark_width$margin_x$position[0]), wm_pos($image_height$watermark_height$margin_y$position[1]), 0, 0, $watermark_info[0], $watermark_info[1], $opacity); //Using the "wm_pos" function & "position" array

}





// send out a header
header("content-type:image/$image_type");

// send the image
eval ("image$image_type (\$image,'',\$quality);");

// clean up
imagedestroy($image);

?>



Quote from: Karri on June 22, 2004, 07:45:08 PM
It should have already worked with PNG or JPG.  It didn't autodetect the type but when you were putting in the name of the watermark image, the very next line was for telling it what type of file it was.

$watermark_image        = "watermark.png";                               // Full path to image
       
       $watermark_type                = "PNG";                                 // JPEG or PNG

I was talking about the watermarkED image, not the watermark, I receave error when I try to watermark .PNG image
(https://coppermine-gallery.com/forum/proxy.php?request=http%3A%2F%2Fwww.danasoft.com%2Fsig%2FFeredzhanov.jpg&hash=301c2542bbd14d4700cb5f2723189d886c069528)

skybax

Does anyone have load stats from their servers when using this script. I like the idea and want to use it, but owners of a site I am building to use it on is projecting 10k-20k pics and a large visitor base. So if this would cause too much strain - should i go with an off server watermarking solution?
(https://coppermine-gallery.com/forum/proxy.php?request=http%3A%2F%2Fwww.skybax.com%2FhotImage%2Fpost_footer.gif&hash=338b65c57a59f0b06311094e697c87794e43d945)
Don't contact me for support over PM or email unless I requested you to do so. Instead: post on the proper board.

Joachim Müller

I recommend going for a solution that applies a watermark once (during upload) to the pic. Applying watermarks "on the fly" each time the pic loads is way to resources-consuming and only meant for users running sites that don't get relevant traffic at all (who have never more than one user online at a time).
The best solution is applying a watermark to the pics on your client before uploading - faster, safer, not so resources-consuming.

GauGau

PCGUY112887

Ok now i'm lost... I remember installing this when this post was first made... now I see a bunch of versions everywhere.  Now which code exactelly should I use, and what instructions?  Maybe we could make a final copy of this with instructions for a sticky?

skybax

There are a slew of these mods running around. To pick one and single it out is not really a sticky solution. But I do agree simplify the posts... by singling out the strength of the different versions. Such as load times, server strain, ability to turn on/off per image....

-T  8)
(https://coppermine-gallery.com/forum/proxy.php?request=http%3A%2F%2Fwww.skybax.com%2FhotImage%2Fpost_footer.gif&hash=338b65c57a59f0b06311094e697c87794e43d945)
Don't contact me for support over PM or email unless I requested you to do so. Instead: post on the proper board.

PCGUY112887

Well I just need something that works with ImageMagik... is easy to install (no editing a million files)... and does it to every file no matter what.  O and works with 1.3.2 :)
Any suggestinons on what to pick?

skybax

Quote from: PCGUY112887 on August 19, 2004, 01:08:18 AM
Well I just need something that works with ImageMagik... is easy to install (no editing a million files)... and does it to every file no matter what.  O and works with 1.3.2 :)
Any suggestinons on what to pick?

The only one I found is located here. It's for 1.2.1 but I think with a little modification it would work with 1.3.2 - I don't have imagemagik so I wouldn't have a way to test... But if you have that installed it would be fun to work on a project. I am currently working on a version compatiable with GD2.0 [1.3.x] and adding multiple features (right now it's in crashed mode on my version of CPG cause of all the features I'm adding to it.) But I hope to have it finished by the end of the month.

-T  8)
(https://coppermine-gallery.com/forum/proxy.php?request=http%3A%2F%2Fwww.skybax.com%2FhotImage%2Fpost_footer.gif&hash=338b65c57a59f0b06311094e697c87794e43d945)
Don't contact me for support over PM or email unless I requested you to do so. Instead: post on the proper board.

Nekto63

How it can be applied to CPG for PHPnuke/Postnuke (cpgnuke122b)?

Instead of a line    return $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);
In a file  functions.inc.php    return path2url($pic_row['filepath'] . $pic_prefix[$mode] . $pic_row['filename']);
How to be?

Joachim Müller

there's no nuke support to be found here - simply because we don't know it. Please do not post nuke related posts on this board.

Joachim

Thursday

Is it normal that after i've applied watermark on a image, when i click on to see the original picture it doesn't work?
I mean, i got only an X and if i check the directory of the image i got this directiry which seems to be correct:

Quote.../logo.php?picturename=albums/France/Meilleures/C%E9r%EAt/014.jpg
I've remplaced my webhost name by periods ;)

Also, after applying watermark, if i change the watermark picture it stills display the old one... Is it my browser cookies?

davidshook

I am sorry if this is answered somewhere in this thread allerady.
How exactly does this MOD work:
1) do all the batch uploaded pictures get watermarked?
-- or, do I get to chose if batch uploaded pictures get watermarked?

2)  do individual uploaded pictures get water marked?
-- do users/members (as opposed to admin level) have any control over the water marking process in this case.

3) what happens when a user uploads video, mp3, zip, pdf file?
-- does the upload faile?
-- does the file become unreadable?


The reason I am asking this is because I am designing a site that will have  a gallery that allows loged-in members to upload there own pictures/videos/documents. I want to have a watermark on the pictures that the users upload. The user should not be able to upload a picture without a water mark (although it is ok if they have a choice where to place the watermark on the picture)

The rest of the galleries are not for uploads by users. For these galleries I do the batch uploading and the pictures are already watermarked on my desktop pc prior to upload.

So, to some it up: all pictures that are uploaded via http/form need to be watermarked.
Batch files should not be watermarked.
Non-picture files should not be a problem (since I do not limit the file type to be uploaded)


I also think that anyone that thinks about using water marking should have these answers before going through the work of installing and testing the MOD's.

Please help, thank's in advance

Nibbler

This is on-the-fly watermarking. It doesn't permanently alter the pics, it just puts a watermark on when the pic is displayed. How the pic is uploaded is irrelevent. There are other mods around for permanent watermarking. I don't know about non-pics, but if it makes problems it's only a 1 line fix to make it skip non images.


trued

i just registered to this forum only to say that this hack worked for me. I followed the instructions exactly and modified the settings in the logo.php file and voila! watermarked images. For those trying to create the watermark image :

on photoshop I  went to

file>new> choose transparent bg and set the size you want it to be.

type in the text or create the image you want to display and thats it. Save as a watermark.png and upload to the root folder.
I noticed that the edges were choppy so I just went back to photoshop and added a black stroke to the text. this hid the choppy edges on lighter backgrounds.

I also was able to update all the pictures i had uploaded before this hack by going into phpmyadmin and editing the table cpg_pictures. in the box just replace :   SELECT * FROM `cpg_pictures`  with  UPDATE `cpg_pictures` SET `user1` = 'YES';...   just as explained by t3kn0byt3 .thank you

of course change the cpg part of cpg_pictures to reflect your prefix.

Any questions you can reply to this and maybe i can help. I am running imagemagik and linux/unix .

thanx to Karri for this great hack!


fedexx

Hello im traying to modify the hack "Watermark on a per image basis " but i have a problem that cannot solve.
I add a option in a "albums options" that it allows to select if I want or not add a  watermark to the pics of the album.
I want to add another option that allows to select that image I want to use, and to be able to use different imagenes for different albums.
Here is the code of "logo.php" i add a conection to the database to obtain the watermark image name´s but that don't works

<?
//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!
define('IN_COPPERMINE', true);
require('include/init.inc.php');
global $CONFIG;

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

        // Full path to image
$album=$pic_row['aid'];
$consulta = db_query("SELECT watermarkdir FROM cpg132_albums WHERE aid = '1'");
$num_filas=mysql_num_rows($consulta);
$array_datos=mysql_fetch_array($consulta);
foreach ($array_datos as $watermark){
        $watermark_image        = "watermark/".$watermark;
}

        $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);


}


seboter

I had some problems to get this hack to work, so I looked through the code and I found something which causes this error and maybe my version will solve other users problems.


So, here we go...

Here is the part of the original code:
Quote######################################################################################################
      ## 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"))
      {

But this will not run on my server!

Here is my version:
Quote######################################################################################################
      ## 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($_GET['picturename']);

        // get the image details and create an image
        $image_width                 = imagesx($file);
        $image_height                = imagesy($file);
        $image                       = $file;

      if (!preg_match("/thumb_/i", $_GET['picturename']))
      {

After this changes this hack works without any problems and instead of the X, I saw before, there is now my picture with the watermark! ;)

Hope it helps you!
<a href="http://www.4edged.com" target="_blank">sebotronik image database</a>

pgrzegorc

Can I used a few watermarks during to upload picturees to my gallery??
for example I have a few categories, a few albums, about 20 person can upload to my gallery and I want during uploding files add to pictures different watermark for different users but I should make it???

Pawel

Summi

Hi,

this mod is working fine, but I've got a question:

while uploading single files, i always have to type "YES" into the user-uield 1.

Could it be possible, that "YES" is automatically the default input to this field ??  (-> with the batch function "yes" is insert automaitcally)

Thanx,
Summi