forum.coppermine-gallery.net

No Support => Modifications/Add-Ons/Hacks => Mods: Watermarking & image manipulation => Topic started by: Sammy on March 05, 2004, 07:53:14 pm

Title: Permanent Watermark with GD2
Post by: Sammy on March 05, 2004, 07:53:14 pm
I have looked script for watermaking images permanent, not on the fly.
Becouse have'nt find any, I decided to try making one.
I'm not good on PHP (or ong english writing), but hope that maybe someone like to test it also.
There maybe many bugs, but I have used on couple hundred images with out problems. I dont take any responsibility, if this code messes your server or images, so be careful  :roll:
And Big thanks for DJ Axion, whose script I have used as base of this script (with util, and picmgmt.php)

REMEMBER to take backup from all files that You are modifying

I have modified util.php, include/picmgmt.inc.php and lang/yourownlanguage.php (finnish.php on my situation)

1.
Lang/finnish.php (english or whatever languageYou are using)
Add new line after line 984 (text):
Code: [Select]
        'select_album' => 'Select album',Paste theese lines:
Code: [Select]
        'watermarks' => 'Add watermaks',
        '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. include/picmgmt.inc.php
Find this part of code (line 190 - 201 ?)
Code: [Select]
            // Set mode of uploaded picture
            chmod($dest_file, octdec($CONFIG['default_file_mode']));
            // We check that the image is valid
            $imginfo = getimagesize($dest_file);
            if ($imginfo == null) {
                $ERROR = $lang_errors['resize_failed'];
                @unlink($dest_file);
                return false;
            } else {
                return true;
            }
        }

Activate all after above code and past all from below
Code: [Select]
        /**
         * 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];
            $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('/your/full/path/to/galleria/include/logo.png'); // logo.png is a watermark it add's...
                                        $logoW = ImageSX($logoImage);
                                        $logoH = ImageSY($logoImage);
                                        //where is the watermark displayed...
                                        $pos = "bottomright";
                                        if ($pos == "topleft") {
                                        $src_x = 5; 
                                        $src_y = 5;
                                        } else if ($pos == "topright") {
                                        $src_x = $srcWidth - ($logoW + 2);
                                        $src_y = 5;
                                        } else if ($pos == "bottomleft") {
                                        $src_x = 5;
                                        $src_y = $srcHeight - ($logoH + 2);
                                        } else if ($pos == "bottomright") {
                                        $src_x = $srcWidth - ($logoW + 2);
                                        $src_y = $srcHeight - ($logoH + 2);
                                        }

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

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

        ?>



I will post last part of modifications, after I have eat the Pizza, that is still warm  :P
Title: Permanent Watermark with GD2
Post by: Sammy on March 05, 2004, 08:58:08 pm
OK, Pizza is destroyed now.

3. util.php
Find line
Code: [Select]
function deleteorig()
Near line 206

Add new line Above text "function deleteorig()"
and paste code from below

Code: [Select]
function vesileimaathumbit()
{
    global $picturetbl, $CONFIG, $lang_util_php;
    $phpself = $_SERVER['PHP_SELF'];
    $albumid = $_POST['albumid'];
    $updatetype = $_POST['updatetype'];
    $numpics = $_POST['numpics'];
    $startpic = 0;
    $startpic = $_POST['startpic'];

    $query = "SELECT * FROM $picturetbl WHERE aid = '$albumid'";
    $result = MYSQL_QUERY($query);
    $totalpics = mysql_numrows($result);

    if ($startpic == 0) {
        // 0 - numpics
        $num = $totalpics;
        // Over picture limit
        if ($totalpics > $numpics) $num = $startpic + $numpics;
    } else {
        // startpic - numpics
        $num = $startpic + $numpics;
        if ($num > $totalpics) $num = $totalpics;
    }

    $i = $startpic;
    while ($i < $num) {
        $image = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") . mysql_result($result, $i, "filename");

        if ($updatetype == 0 || $updatetype == 2) {
            $imagesize = getimagesize($image);
            if (max($imagesize[0], $imagesize[1]) > $CONFIG['picture_width'] && $CONFIG['make_intermediate'])        {
            $image = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") . $CONFIG['normal_pfx'] . mysql_result($result, $i, "filename");
                        }        else        {
            $image = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") . mysql_result($result, $i, "filename");
                        }

            if (watermark($image)) {
                print $image .' '. $lang_util_php['updated_succesfully'] . '!<br />'; //$normal .' '. $lang_util_php['updated_succesfully'] . '!<br />';
                my_flush();
            } else {
                print $lang_util_php['error_create'] . ':$image<br />'; //$lang_util_php['error_create'] . ':$normal<br />';
                my_flush();
            }
        }

        if ($updatetype == 1 || $updatetype == 2) {
            $image = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") . mysql_result($result, $i, "filename");

            if (watermark($image)) {
                print $image .' '. $lang_util_php['updated_succesfully'] . '!<br />'; //$normal .' '. $lang_util_php['updated_succesfully'] . '!<br />';
                my_flush();
            } else {
                print $lang_util_php['error_create'] . ':$image<br />'; //$lang_util_php['error_create'] . ':$normal<br />';
                my_flush();
            }
        }

        ++$i;
    }
    $startpic = $i;

    if ($startpic < $totalpics) {

        ?>
            <form action=<?php echo $phpself;
        
?>
method="post">
                    <input type="hidden" name="action" value="continuewatermarks" />
                    <input type="hidden" name="numpics" value="<?php echo $numpics?>" />
                    <input type="hidden" name="startpic" value="<?php echo $startpic?>" />
                    <input type="hidden" name="updatetype" value="<?php echo $updatetype?>" />
            <input type="hidden" name="albumid" value="<?php echo $albumid?>" />
            <input type="submit" value="<?php print $lang_util_php['continue'&#93;;
        
?>
" class="submit" /></form>
                    <?php
    
&#125;
&#125;


Between lines
Code: [Select]
updatethumbs(); (last one, near line 358)
and
Code: [Select]
filenametotitle(0); (should be only few lines after "updatethumbs();" )

Paste this code
Code: [Select]

    echo '<br /><a href="' . $phpself . '">' . $lang_util_php['back'] . '</a>';
} else if ($action == 'watermarks') {//tämä
    global $picturetbl, $CONFIG;
    print '<a href="' . $phpself . '">' . $lang_util_php['back'] . '</a><br />';
    print '<h2>' . $lang_util_php['watermark_wait'] . '</h2>';

    vesileimaathumbit();

    echo '<br /><a href="' . $phpself . '">' . $lang_util_php['back'] . '</a>';
} else if ($action == 'continuewatermarks') {//tämä
    print '<a href="' . $phpself . '">' . $lang_util_php['back'] . '</a><br />';
    print '<h2>' . $lang_util_php['watermark_wait'] . '</h2>';

    vesileimaathumbit();

    echo '<br /><a href="' . $phpself . '">' . $lang_util_php['back'] . '</a>';

} else if ($action == 'title') {
    echo '<a href="' . $phpself . '">' . $lang_util_php['back'] . '</a><br />';
    print '<h2>' . $lang_util_php['titles_wait'] . '</h2>';
(yes, You should replace few lines. Yes, the lines are identical, but I dont know how to describe it beter in english  :D )

Then You have to find this
Code: [Select]
print '<br />';

    starttable('100%', '<input type="radio" name="action" value="title" id="title" class="nobg" /><label for="title" accesskey="F" class="labelradio">' . $lang_util_php['filename_title'] . '</label> (1)');
(Near line 442)

On the empty line between, add new line and put this
Code: [Select]
   starttable('100%', '<input type="radio" name="action" value="watermarks" id="watermarks" class="nobg" /><label for="watermarks" accesskey="w" class="labelradio">' . $lang_util_php['watermarks'] . '</label> (1)');
    print '
<tr><td>
' . $lang_util_php['update_what'] . ' (2):<br />
<input type="radio" name="updatetype" value="0" id="thumb" class="nobg" /><label for="thumb" accesskey="w" class="labelradio">' . $lang_util_php['watermark_normal'] . '</label><br />
<input type="radio" name="updatetype" value="1" id="resized" class="nobg" /><label for="resized" accesskey="r" class="labelradio">' . $lang_util_php['watermark_image'] . '</label><br />
<input type="radio" name="updatetype" value="2" checked="checked" id="all" class="nobg" /><label for="all" accesskey="a" class="labelradio">' . $lang_util_php['watermark_both'] . '</label><br />
' . $lang_util_php['update_number'] . '
<input type="text" name="numpics" value="' . $defpicnum . '" size="5" /><br />
' . $lang_util_php['update_option'] . '<br /><br />
</td></tr>';
    endtable();

    print '<br />';
on new line that You just created.


If everything has been done fine, You can now add watermarks on albums by going to "Resize Pictures". there should be new section: "Add watermarks". Just select imagesizes You want to be watermarked, and at the bottom of page, select album what You are going to watermark images in.

There should also be .PNG image "called logo.png". In my case, logo.png is on includes folder. If your logo.png is 30% trnsparent, then You get transparent watermark
You should also change the full path to point correct file (logo.png, or what ever Your watermark image is called)


Hope that I remember to put everything in it :?
Title: Permanent Watermark with GD2
Post by: Ravage on March 06, 2004, 12:32:52 am
Great job! Will try it out later.
Title: Permanent Watermark with GD2
Post by: Zcaithaca on March 18, 2004, 03:36:19 am
srry if this is a newbie question but where is the resize image thing located?
Title: Resize image
Post by: Sammy on March 18, 2004, 08:17:20 am
Quote from: "Zcaithaca"
srry if this is a newbie question but where is the resize image thing located?

When you are logged in as an admin, the script has two modes of operation : Admin mode & User mode. You switch between Admin & User mode by clicking on the corresponding link in the menu bar at the top of the screen.

When you are in admin mode, you can administer your gallery and the following menu bar appears :
(http://coppermine.sourceforge.net/images/admin_mode_bar.gif)

Resize Pictures is located on menu bar. It is not showing on above image, becouse ist from an older version of Coppermine, but it is between "Batch add pictures" and "My profile" buttons.
Title: Permanent Watermark with GD2
Post by: Casper on March 18, 2004, 12:37:49 pm
Addition to above, the link is not shown in the hardwired theme.
Title: Permanent Watermark with GD2
Post by: Zcaithaca on March 18, 2004, 10:48:05 pm
ok thx im using the hardwired so ill change it
Title: Permanent Watermark with GD2
Post by: photoman13 on March 20, 2004, 05:51:21 am
anyone have a sample gallery that is using this? for us to see?

Will the watermark covert the full pic? or is it just on a corner of a picture?

Thanks :)
Title: Sample gallery
Post by: Sammy on March 23, 2004, 11:13:06 am
Here is one gallery where I'm using it.
http://www.jarnokalliomaki.com/index_carry.shtml

There are sometimes pics with out watermarks, becouse pics are added after watermarking that album.
You could ofcource move images to some temporary album and watermark pics in there. that way You do not get Your images watermarked many times and loose transparency of watermark.

On the other albums there are also watermarked pics done by Our old imagegallery, but most of watermarks are done on old gallery with imagemagick.


I will try to add same watermarking on "batch add pictures" page, so I get all new images automatically watermarked, while waiting CPG 1.3  :D
Title: GD2 watermarking
Post by: Sammy on March 23, 2004, 11:31:16 am
Quote from: "photoman13"

Will the watermark covert the full pic? or is it just on a corner of a picture?

Watermark will convert ful pic.
It will be on corner. You can decide corner You want, by changing it on include/picmgmt.inc.php .
Title: Permanent Watermark with GD2
Post by: Tarique Sani on March 26, 2004, 11:14:03 am
Can you zip up the relevant files and post a link OR sent it to me

I will incorporate it into the main CPG (of course your name will be in the credits)
Title: GD2 watermarking files in ZIP
Post by: Sammy on March 26, 2004, 12:10:22 pm
Hello Tarique

Here is link to zip
Permanent Watermark with GD2 (http://www.sammy.fi/coppermine_gd2wm/GD2_Watermarking.zip)

This link will work for now, but I'm doing some changes on my website, so I dont know how long it will be there. But at least for couple weeks.


You could possible do some check on those code changes. I think there are some duplications on variable names on watermark_image() function on /include/picmgmt.inc.php.
Title: Permanent Watermark with GD2
Post by: Tarique Sani on March 26, 2004, 12:52:00 pm
Thanks - I have got the file, will look into the code and incorporate accordingly
Title: Permanent Watermark with GD2
Post by: photoman13 on March 26, 2004, 09:02:32 pm
Sammy,

awesome coding there.. I got it working on 2 of my galleries :)

question: so now that it's installed... whenever someone uploads a photo is it automatically 'watermarked' or do we always have to go in and do it manually?
Sorry.. I haven't had any new photos to test that on... and thought I would ask :)

Thanks again for the code.. it was easy to install :)

As for the Hardwire theme, it was still easy to do, just changed the theme back to default and did the resizing (watermarking) there.. then changed it back when I was done :)
Title: Permanent Watermark with GD2
Post by: Casper on March 26, 2004, 09:11:41 pm
@photoman,

you don't have to change theme, just type in the url direct, i.e., yoursite.com/gallery/util.php
Title: Permanent Watermark with GD2
Post by: Sammy on March 26, 2004, 10:08:00 pm
Quote from: "photoman13"
Sammy,

awesome coding there.. I got it working on 2 of my galleries :)

question: so now that it's installed... whenever someone uploads a photo is it automatically 'watermarked' or do we always have to go in and do it manually?


It does not add watermark automatically  :cry:
I'm trying to get it work automatically when adding new pics, and if I succes in the process, I'll post code it here.


If You do keep albums, where You are adding pics, You need to create some temporary album, where to upload pics and watermark those in that album and move all images after watermarking to desired album.

If You Just add more pics to some album and watermark pics there, Your older (allready watermarked pics) are going to loose some of quality and transparency of Your logo.png watermark, becouse it just stamps watermark again in all pics.
Title: Permanent Watermark with GD2
Post by: photoman13 on March 26, 2004, 10:26:57 pm
thanks Sammy :)

I'll just do it that way til you get that process complete :)

it's still a great addition :)
Title: Now it also add watermarks, when adding new images!!!
Post by: Sammy on March 26, 2004, 11:27:30 pm
Quote from: "photoman13"
Sammy,

question: so now that it's installed... whenever someone uploads a photo is it automatically 'watermarked' or do we always have to go in and do it manually?


 :D  :D  :D
By the power of friday Sauna and cold beer after it, here it comes...

First I need to say: This is NOT tested yet with couple hundreds of pics, but only few test images.


1
You need to add all modifications mentioned on this topics 1st and 2nd post.

2
Open Your modified /include/picmgmt.inc.php and find line 34. It should look like this:
Code: [Select]
               return false;

3
Add theese new lines after line 34
Code: [Select]


                //Adds watermarks to new images
        if (!watermark($image))  //this is for full size image
            return false;
        if (!watermark($normal))  //this is for intermediate size image
            return false;


Thats it.
Now You have watermark automatic :)

Just to make it sure, Your first 42 lines of code should be look like this:.
Code: [Select]
<?php 
// ------------------------------------------------------------------------- //
// Coppermine Photo Gallery 1.2.1                                            //
// ------------------------------------------------------------------------- //
// Copyright &#40;C&#41; 2002,2003 Gregory DEMAR                                     //
// http&#58;//www.chezgreg.net/coppermine/                                       //
// ------------------------------------------------------------------------- //
// Updated by the Coppermine Dev Team                                        //
// &#40;http&#58;//coppermine.sf.net/team/&#41;                                          //
// see /docs/credits.html for details                                        //
// ------------------------------------------------------------------------- //
// This program is free software; you can redistribute it and/or modify      //
// it under the terms of the GNU General Public License as published by      //
// the Free Software Foundation; either version 2 of the License, or         //
// &#40;at your option&#41; any later version.                                       //
// ------------------------------------------------------------------------- //
// Add a picture to an album
function add_picture&#40;$aid, $filepath, $filename, $title = '', $caption = '', $keywords = '', $user1 = '', $user2 = '', $user3 = '', $user4 = '', $category = 0, $raw_ip = '', $hdr_ip = ''&#41;
&#123;
    
global $CONFIG$ERROR$USER_DATA$PIC_NEED_APPROVAL;
    global 
$lang_errors;

    
$image $CONFIG['fullpath'&#93; . $filepath . $filename;
    
$normal $CONFIG['fullpath'&#93; . $filepath . $CONFIG['normal_pfx'&#93; . $filename;
    
$thumb $CONFIG['fullpath'&#93; . $filepath . $CONFIG['thumb_pfx'&#93; . $filename;

    
$imagesize getimagesize&#40;$image&#41;;
    
if &#40;!file_exists&#40;$thumb&#41;&#41;
        
if &#40;!resize_image&#40;$image, $thumb, $CONFIG['thumb_width'&#93;, $CONFIG['thumb_method'&#93;, $CONFIG['thumb_use'&#93;&#41;&#41;
            
return false;

        if &
#40;max&#40;$imagesize[0&#93;, $imagesize[1&#93;&#41; > $CONFIG['picture_width'&#93; && $CONFIG['make_intermediate'&#93; && !file_exists&#40;$normal&#41;&#41;
            
if &#40;!resize_image&#40;$image, $normal, $CONFIG['picture_width'&#93;, $CONFIG['thumb_method'&#93;, $CONFIG['thumb_use'&#93;&#41;&#41;
                
return false;

                
//Adds watermarks to new images
        
if &#40;!watermark&#40;$image&#41;&#41;  //this is for full size image
            
return false;
        if &
#40;!watermark&#40;$normal&#41;&#41;  //this is for intermediate size image
            
return false;

            
$image_filesize filesize&#40;$image&#41;;



PS.
Remember to CHMOD every pic uploaded with FTP to 666, or You'll get some errors becouse You have not give apache/PHP right to save modified pics.


Tarique
I will change the zip file for You, but I will do it on monday, when Im on work
Title: Permanent Watermark with GD2
Post by: photoman13 on March 27, 2004, 12:01:19 am
Hey Sammy :)

good work :)

I'm gonna go test that myself right now :)

I'll let ya know :)
Title: Permanent Watermark with GD2
Post by: photoman13 on March 27, 2004, 12:05:15 am
awesome Sammy.. it works for me :)

Thanks again for this great mod!!! :)
Title: Permanent Watermark with GD2
Post by: Burpee on March 29, 2004, 01:21:05 am
 
*ahem*


okay, it's 1:30 am and I've got 5 and a half hours of sleep ahead of me so I wanna make this quick...
I've installed the mod on my gallery... I'm not very good at PHP, but I'm learning steadily.

When I try uploading a foto normally (with watermark on upload) it gives me the following error:

Quote
De foto 'albums/userpics/10001/592314802.jpg' kan niet ingevoegd worden in het album.


Warning: getimagesize(albums/userpics/10001/normal_592314802.jpg): failed to open stream: No such file or directory in /home/vuurwerk/public_html/galleryhidden/include/picmgmt.inc.php on line 224

now... it could just be something stupid I did... I dunno..

thanx in advance :D


Burpee
Title: Permanent Watermark with GD2
Post by: Tarique Sani on March 29, 2004, 07:15:12 am
Thanks - the whole thing of
1)watermark image on upload,
2)where to place the watermark,
3)which file to use for watermark
4)which files to watermark

Needs to be admin settable - are you feeling upto doing that as well?

Once you are thru I intend to write a watermark function for Image MagicK and we would  have completed the Watermark feature :)
Title: Watermarking settings
Post by: Sammy on March 29, 2004, 11:41:16 am
Quote from: "tarique"
Thanks - the whole thing of
1)watermark image on upload,
2)where to place the watermark,
3)which file to use for watermark
4)which files to watermark

Needs to be admin settable - are you feeling upto doing that as well?

Once you are thru I intend to write a watermark function for Image MagicK and we would  have completed the Watermark feature :)


I dont know if I have knowledge to do it, but I will try.
Correct if I go wrong in first step: config values should be saved into table named "someprefix_config"?
And I think those settings should be settable from config.php?
Title: Permanent Watermark with GD2
Post by: Sammy on March 29, 2004, 11:43:40 am
Quote from: "Burpee"

When I try uploading a foto normally (with watermark on upload) it gives me the following error:

Quote
De foto 'albums/userpics/10001/592314802.jpg' kan niet ingevoegd worden in het album.


Warning: getimagesize(albums/userpics/10001/normal_592314802.jpg): failed to open stream: No such file or directory in /home/vuurwerk/public_html/galleryhidden/include/picmgmt.inc.php on line 224


now... it could just be something stupid I did... I dunno..

Hi Burbee

I'll try to check it.
What does "De foto 'albums/userpics/10001/592314802.jpg' kan niet ingevoegd worden in het album" mean in english?
Title: Re: Watermarking settings
Post by: Tarique Sani on March 29, 2004, 12:41:02 pm
Quote from: "Sammy"
I dont know if I have knowledge to do it, but I will try.
Correct if I go wrong in first step: config values should be saved into table named "someprefix_config"?
And I think those settings should be settable from config.php?


As long as you are willing to learn we will be willing to help :) Here are some tips to get you started

To add an option to the Config screen you need to
1) edit the language file for example open english.php and search for "config.php" below that you will find all the arrays which are needed to create the config screen. Since you will be mostly adding "yes"  "no" options what you need to add is something like this
Code: [Select]
array('Watermark Image on upload', 'enable_watermark', 1),

2) You need to add a record to the cpg_config table with name = "enable_watermark"

3) Then in your scripts the state of "enable_watermark" will be available in
Code: [Select]
$CONFIG['enable_watermark']

Try it out and let me know if you need further help :)
Title: Something done with watermarking...
Post by: Sammy on March 29, 2004, 09:57:58 pm
@Tarique

Thanks for tips!
I have now done it to admin settings.
Now I try to get those watermark scripts to understand those admin settings.

By the way, if You have looked modified picmgmt.inc.php, tell Me if next part is needed at all?
Code: [Select]
           $imginfo = getimagesize($src_file);
            if ($imginfo == null) {
                $ERROR = $lang_errors['resize_failed'];
                @unlink($src_file);
                return false;
            } else {
                return true;
            }


I wonder it becouse just checked about @unlink() function, and noticed that it's for deleting a file.
Title: Permanent Watermark with GD2
Post by: Sammy on March 29, 2004, 10:15:04 pm
@ Burpee

Is there possibility, that image that gave error, is so small that there are no original and normal (resized) image?
I've got same error, when trying to upload small pic.

We need to make check in watermarking, so there wont come that error, if pic is smaller than size of intermediate picture.
Title: Permanent Watermark with GD2
Post by: Burpee on March 29, 2004, 10:19:28 pm
Quote from: "Sammy"
Quote from: "Burpee"

When I try uploading a foto normally (with watermark on upload) it gives me the following error:

Quote
De foto 'albums/userpics/10001/592314802.jpg' kan niet ingevoegd worden in het album.


Warning: getimagesize(albums/userpics/10001/normal_592314802.jpg): failed to open stream: No such file or directory in /home/vuurwerk/public_html/galleryhidden/include/picmgmt.inc.php on line 224


now... it could just be something stupid I did... I dunno..

Hi Burbee

I'll try to check it.
What does "De foto 'albums/userpics/10001/592314802.jpg' kan niet ingevoegd worden in het album" mean in english?


I think it was just an error I made somehow. It's working fine now anyway. Maybe I was doing something stupid but I wasn't entirely awake when I wrote the previous post, sorry about that.

I'm loving the mod tho...
one aspect I am worried about, is it still possible to upload movies? I know there's already a discussion about this in "Coppermine should also allow video" but I think that the creator of the watermark mod has a better perspective on possible solutions :D

Seeing as I'm not very experienced in php I might be sounding stupid as hell, but isn't it just as simple as just telling the watermark code to ignore all formats other than jpg and png?

When I upload a movie it just tells me (roughly translated):
Quote
The photo 'albums/userpics/10001/cube1.mpg' cannot be inserted to the album.

If you are using the GD image library only the formats JPG and PNG are allowed.

But to be quite honest I just realized this is the first time I've tested the movie upload function.... hmm... if only I had more time so I could test everything every time I wanted to... but hey time is scarce
Title: Permanent Watermark with GD2
Post by: Sammy on March 29, 2004, 10:50:40 pm
@Burpee
I cant help You with that movie uploading right now.
I think it can be quite easy to by pass watermarking of anything else, than JPG or PNG, but not sure about it.
Maybe Tarique or some other Guru can tell, if putting "break" or some  other "get a way from this watermarking function"-command on watermark scripts imagetype checking part would do that?
Code: [Select]

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


I'm working now with those admin settings on watermarking.
There will be (actually I have done that part allready) easy way to turn watermarking off from the setings. So at least You can drop watermarking off when uploading movies and turn it back when you want it.
Title: GD2 Watermark
Post by: Sammy on March 30, 2004, 12:00:46 am
Quote from: "tarique"
Thanks - the whole thing of
1)watermark image on upload,
2)where to place the watermark,
3)which file to use for watermark
4)which files to watermark

Needs to be admin settable - are you feeling upto doing that as well?

Once you are thru I intend to write a watermark function for Image MagicK and we would  have completed the Watermark feature :)


@Tarique
It's done with Your great tips, that lead me to succes :D
Dont know about how clean code it is, but it's working.

I updated the zip file (http://www.sammy.fi/coppermine_gd2wm/GD2_Watermarking.zip) and added 4 SQL insert lines in txt file.

There needs to be done check for image size.
If (image size <= intermediate image size on settings) {
  no need to watermark intermediateprefix_imagename;
  Break (or some command to stop watermarking of this pic);
}
Title: Re: GD2 Watermark
Post by: Tarique Sani on March 30, 2004, 05:20:38 am
Quote from: "Sammy"
@Tarique It's done with Your great tips, that lead me to succes :D
Dont know about how clean code it is, but it's working.

Great work!! 8)
I will look into the code in a day or two I am busy with some interviews right now

Thanks
Title: Permanent Watermark with GD2
Post by: Sammy on March 30, 2004, 10:58:37 pm
For CPG users who wants to add GD2 watermark function on their gallery.

This MOD uses GD2!

Here is how to mod (original) CPG 1.2.1 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


You can download modified files in a zip file from here (http://www.sammy.fi/coppermine_gd2wm/GD2_Watermarking.zip), or You can do modifications by Your self.


1.
Open file Lang/english.php

Find this:
Code: [Select]
'th_wd' => 'Width',

Add this after it
Code: [Select]

                '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:
Code: [Select]
array('Enable debug mode', 'debug_mode', 1),

Add this after it
Code: [Select]


                'Image watermarking',
                array('Watermark Image on upload', 'enable_watermark', 1),
                array('Where to place the watermark', 'where_put_watermark', 8),
                array('which files to watermark', 'which_files_to_watermark', 9),
                array('Which file to use for watermark', 'watermark_file', 0),


Find this:
Code: [Select]
'select_album' => 'Select album',

Add this after it
Code: [Select]

        'watermarks' => 'Add watermaks',
        '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:
Code: [Select]
$image_filesize = filesize($image);

Add this before it
Code: [Select]

                //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 (!watermark($normal))  //this is for intermediate size image
            return false;
                }
               


Find this:
Code: [Select]
?>

Add this before it
Code: [Select]

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




3.
Open File util.php

Find this:
Code: [Select]
function deleteorig()

Add this before it
Code: [Select]

function vesileimaathumbit()   //watermarkthumbs
{
    global $picturetbl, $CONFIG, $lang_util_php;
    $phpself = $_SERVER['PHP_SELF'];
    $albumid = $_POST['albumid'];
    $updatetype = $_POST['updatetype'];
    $numpics = $_POST['numpics'];
    $startpic = 0;
    $startpic = $_POST['startpic'];

    $query = "SELECT * FROM $picturetbl WHERE aid = '$albumid'";
    $result = MYSQL_QUERY($query);
    $totalpics = mysql_numrows($result);

    if ($startpic == 0) {
        // 0 - numpics
        $num = $totalpics;
        // Over picture limit
        if ($totalpics > $numpics) $num = $startpic + $numpics;
    } else {
        // startpic - numpics
        $num = $startpic + $numpics;
        if ($num > $totalpics) $num = $totalpics;
    }

    $i = $startpic;
    while ($i < $num) {
        $image = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") . mysql_result($result, $i, "filename");

        if ($updatetype == 0 || $updatetype == 2) {
            $imagesize = getimagesize($image);
            if (max($imagesize[0], $imagesize[1]) > $CONFIG['picture_width'] && $CONFIG['make_intermediate'])        {
            $image = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") . $CONFIG['normal_pfx'] . mysql_result($result, $i, "filename");
                        }        else        {
            $image = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") . mysql_result($result, $i, "filename");
                        }

            if (watermark($image)) {
                print $image .' '. $lang_util_php['updated_succesfully'] . '!<br />'; //$normal .' '. $lang_util_php['updated_succesfully'] . '!<br />';
                my_flush();
            } else {
                print $lang_util_php['error_create'] . ':$image<br />'; //$lang_util_php['error_create'] . ':$normal<br />';
                my_flush();
            }
        }

        if ($updatetype == 1 || $updatetype == 2) {
            $image = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") . mysql_result($result, $i, "filename");

            if (watermark($image)) {
                print $image .' '. $lang_util_php['updated_succesfully'] . '!<br />'; //$normal .' '. $lang_util_php['updated_succesfully'] . '!<br />';
                my_flush();
            } else {
                print $lang_util_php['error_create'] . ':$image<br />'; //$lang_util_php['error_create'] . ':$normal<br />';
                my_flush();
            }
        }

        ++$i;
    }
    $startpic = $i;

    if ($startpic < $totalpics) {

        ?>
            <form action=<?php echo $phpself;
        
?>
method="post">
                    <input type="hidden" name="action" value="continuewatermarks" />
                    <input type="hidden" name="numpics" value="<?php echo $numpics?>" />
                    <input type="hidden" name="startpic" value="<?php echo $startpic?>" />
                    <input type="hidden" name="updatetype" value="<?php echo $updatetype?>" />
            <input type="hidden" name="albumid" value="<?php echo $albumid?>" />
            <input type="submit" value="<?php print $lang_util_php['continue'&#93;;
        
?>
" class="submit" /></form>
                    <?php
    
&#125;
&#125;  



Find this:
Code: [Select]
filenametotitle(0);

Add this before it
Code: [Select]


    echo '<br /><a href="' . $phpself . '">' . $lang_util_php['back'] . '</a>';
} else if ($action == 'watermarks') {//tämä
    global $picturetbl, $CONFIG;
    print '<a href="' . $phpself . '">' . $lang_util_php['back'] . '</a><br />';
    print '<h2>' . $lang_util_php['watermark_wait'] . '</h2>';

    vesileimaathumbit();  //watermarkthumbs

    echo '<br /><a href="' . $phpself . '">' . $lang_util_php['back'] . '</a>';
} else if ($action == 'continuewatermarks') {//tämä
    print '<a href="' . $phpself . '">' . $lang_util_php['back'] . '</a><br />';
    print '<h2>' . $lang_util_php['watermark_wait'] . '</h2>';

    vesileimaathumbit();  //watermarkthumbs


Find this:
Code: [Select]
starttable('100%', '<input type="radio" name="action" value="title" id="title" class="nobg"
(only part of that line)

Add this before it
Code: [Select]

//This is for watermarking
    starttable('100%', '<input type="radio" name="action" value="watermarks" id="watermarks" class="nobg" /><label for="watermarks" accesskey="w" class="labelradio">' . $lang_util_php['watermarks'] . '</label> (1)');
    print '
<tr><td>
' . $lang_util_php['update_what'] . ' (2):<br />
<input type="radio" name="updatetype" value="0" id="thumb" class="nobg" /><label for="thumb" accesskey="w" class="labelradio">' . $lang_util_php['watermark_normal'] . '</label><br />
<input type="radio" name="updatetype" value="1" id="resized" class="nobg" /><label for="resized" accesskey="r" class="labelradio">' . $lang_util_php['watermark_image'] . '</label><br />
<input type="radio" name="updatetype" value="2" checked="checked" id="all" class="nobg" /><label for="all" accesskey="a" class="labelradio">' . $lang_util_php['watermark_both'] . '</label><br />
' . $lang_util_php['update_number'] . '
<input type="text" name="numpics" value="' . $defpicnum . '" size="5" /><br />
' . $lang_util_php['update_option'] . '<br /><br />
</td></tr>';
    endtable();

    print '<br />';




4.
Open file config.php

Find this:
Code: [Select]
function create_form(&$data)

Add this above it
Code: [Select]

// Added for allowing user to select where to add watermarks on pics...
function form_watermark($text, $name)
{
    global $CONFIG, $lang_config_php;

    $value = $CONFIG[$name];
    $bottomright_selected = ($value == 'bottomright') ? 'selected' : '';
    $bottomleft_selected = ($value == 'bottomleft') ? 'selected' : '';
    $topleftt_selected = ($value == 'topleftt') ? 'selected' : '';
    $topright_selected = ($value == 'topright') ? 'selected' : '';

    echo <<<EOT
        <tr>
            <td class="tableb">
                        $text
        </td>
        <td class="tableb" valign="top">
                        <select name="$name" class="listbox">
                                <option value="bottomright" $bottomright_selected>{$lang_config_php['wm_bottomright']}</option>
                                <option value="bottomleft" $bottomleft_selected>{$lang_config_php['wm_bottomleft']}</option>
                                <option value="topleftt" $topleftt_selected>{$lang_config_php['wm_topleftt']}</option>
                                <option value="topright" $topright_selected>{$lang_config_php['wm_topright']}</option>
                        </select>
                </td>
        </tr>

EOT;
}
// Added for allowing user to select which files to watermark...
function form_watermark2($text, $name)
{
    global $CONFIG, $lang_config_php;

    $value = $CONFIG[$name];
    $both_selected = ($value == 'both') ? 'selected' : '';
    $original_selected = ($value == 'original') ? 'selected' : '';
    $resized_selected = ($value == 'resized') ? 'selected' : '';

    echo <<<EOT
        <tr>
            <td class="tableb">
                        $text
        </td>
        <td class="tableb" valign="top">
                        <select name="$name" class="listbox">
                                <option value="both" $both_selected>{$lang_config_php['wm_both']}</option>
                                <option value="original" $original_selected>{$lang_config_php['wm_original']}</option>
                                <option value="resized" $resized_selected>{$lang_config_php['wm_resized']}</option>
                        </select>
                </td>
        </tr>

EOT;
}



Find this:
Code: [Select]
// Add triple dropdwon later - put back in for compatibility reasons

Few lines below is
Code: [Select]
die('Invalid action');

Now we need to paste this
Code: [Select]

                //Watermark place
                case 8 :
                    form_watermark($element[0], $element[1]);
                                        break;
                                //Which filest to watermark
                case 9 :
                    form_watermark2($element[0], $element[1]);
                                        break;
                case 10 :
                    // do nothing
                    break;
                default:
                   
between them.

After You have done it, it should look like this (I have put couple lines befor and after those lines in this example (hoppe You got it, becouse of My poor english :?
Code: [Select]

                // Thumbnail scaling
                case 7 :
                    form_scale($element[0], $element[1]);
                    break;  // Add triple dropdwon later - put back in for compatibility reasons
                //Watermark place
                case 8 :
                    form_watermark($element[0], $element[1]);
                                        break;
                                //Which filest to watermark
                case 9 :
                    form_watermark2($element[0], $element[1]);
                                        break;
                case 10 :
                    // do nothing
                    break;
                default:
                    die('Invalid action');
            } // switch
        } else {
            form_label($element);



5.
Then You need to execute theese SQL commands with phpMyAdmin or Webmin, etc.

Code: [Select]
insert into cpg11d_config (name, value) values ('enable_watermark', '1');
insert into cpg11d_config (name, value) values ('where_put_watermark', 'bottomright');
insert into cpg11d_config (name, value) values ('watermark_file', '/your/full/path/to/logo.png');
insert into cpg11d_config (name, value) values ('which_files_to_watermark', 'both');



Thats it. Now You can go to setting and set it up.
Actually You need to go there, before trying to add new pics.
You have to chage 'Which file to use for watermark' to point in Your ow transparen logo.png file that is used as watermark.

There is no check for Your intermediate sized pictures, so if Your pics are smaller that intermediate pic size, You'll get errors for no image found.[b/]
There are some solution to come for that problem.


This should contain every modification I have made.
Title: Permanent Watermark with GD2
Post by: raindeer on March 31, 2004, 07:04:20 am
hello sammy,

 I tried your changes on a new just installed photo album, then when trying to upload the photo;s I got this two messages...

Warning: getimagesize(): Unable to access albums/userpics/normal_strand-0030.jpg in /home/httpd/vhosts/partypicas.nl/httpdocs/copper/include/picmgmt.inc.php on line 231

Warning: getimagesize(albums/userpics/normal_strand-0030.jpg): failed to open stream: No such file or directory in /home/httpd/vhosts/partypicas.nl/httpdocs/copper/include/picmgmt.inc.php on line 231

 It's some hours and reinstallations later.... and still the same problem...

Have you got any idea's ???

Reinier
Title: Permanent Watermark with GD2
Post by: raindeer on March 31, 2004, 07:29:03 am
sorry,

 I have read it here before, the resizing was the problem,
my imported images were smaller than the risize sizes....

 so the problem is solved...

 or maybe it is possible to make somewhere an if parameter, when the original is smaller than the risize size....  

 ps I'm an absolute no-no in php....

Reinier
Title: Permanent Watermark with GD2
Post by: Sammy on March 31, 2004, 07:35:51 am
Quote from: "raindeer"
sorry,

 I have read it here before, the resizing was the problem,
my imported images were smaller than the risize sizes....


 or maybe it is possible to make somewhere an if parameter, when the original is smaller than the risize size....  

Reinier


@raindeer

I am working with that image size problem, but i'm not a guru PHP, so it takes time :(
I hope I get it tonight
Title: Permanent Watermark with GD2
Post by: Nawaf on March 31, 2004, 07:48:28 am
Hi,

i tried it but i got this error when i tried to Make the settings from control panel

Watermarking images...

Warning: imagesx(): supplied argument is not a valid Image resource in /home/content/d/o/c/docarabiacom/html/cpg/include/picmgmt.inc.php on line 275

Warning: imagesy(): supplied argument is not a valid Image resource in /home/content/d/o/c/docarabiacom/html/cpg/include/picmgmt.inc.php on line 276

Warning: imagecopy(): supplied argument is not a valid Image resource in /home/content/d/o/c/docarabiacom/html/cpg/include/picmgmt.inc.php on line 293
albums/userpics/infarct.jpg updated succesfully!

Warning: imagesx(): supplied argument is not a valid Image resource in /home/content/d/o/c/docarabiacom/html/cpg/include/picmgmt.inc.php on line 275

Warning: imagesy(): supplied argument is not a valid Image resource in /home/content/d/o/c/docarabiacom/html/cpg/include/picmgmt.inc.php on line 276

Warning: imagecopy(): supplied argument is not a valid Image resource in /home/content/d/o/c/docarabiacom/html/cpg/include/picmgmt.inc.php on line 293
albums/userpics/infarct.jpg updated succesfully!

Warning: imagesx(): supplied argument is not a valid Image resource in /home/content/d/o/c/docarabiacom/html/cpg/include/picmgmt.inc.php on line 275

Warning: imagesy(): supplied argument is not a valid Image resource in /home/content/d/o/c/docarabiacom/html/cpg/include/picmgmt.inc.php on line 276

Warning: imagecopy(): supplied argument is not a valid Image resource in /home/content/d/o/c/docarabiacom/html/cpg/include/picmgmt.inc.php on line 293
albums/userpics/art_normal.jpg updated succesfully!

Warning: imagesx(): supplied argument is not a valid Image resource in /home/content/d/o/c/docarabiacom/html/cpg/include/picmgmt.inc.php on line 275

Warning: imagesy(): supplied argument is not a valid Image resource in /home/content/d/o/c/docarabiacom/html/cpg/include/picmgmt.inc.php on line 276

Warning: imagecopy(): supplied argument is not a valid Image resource in /home/content/d/o/c/docarabiacom/html/cpg/include/picmgmt.inc.php on line 293
albums/userpics/art_normal.jpg updated succesfully!
Title: Permanent Watermark with GD2
Post by: Tarique Sani on March 31, 2004, 07:48:44 am
I am sorry I don't get what the problem is if it is just a question of normal_ not being present put a @in front and the warning will not be displayed - if this hack is not acceptable then do a
Code: [Select]
print_r($CONFIG)

Look up which value you want to test for and put an if condition
Title: Permanent Watermark with GD2
Post by: Sammy on March 31, 2004, 10:47:46 am
@Tarique

I have tried to add an if condition for watermarkin normal sized pics

I was thinking something like
Code: [Select]


                if (max($imagesize[0], $imagesize[1]) > $CONFIG['picture_width'] && $CONFIG['make_intermediate'] && !file_exists($normal) {
                        if ($CONFIG['enable_watermark'] == '1' && $CONFIG['which_files_to_watermark'] == 'both' || $CONFIG['which_files_to_watermark'] == 'resized') {
                                if (!watermark($normal))  //this is for intermediate size image
                                return false;
                        }
                }

in add_picture function where it triggers watermarking for new pics.

What does the ! mark do before !file_exists function in first if condition above? :oops:
Title: Permanent Watermark with GD2
Post by: Tarique Sani on March 31, 2004, 11:22:55 am
the ! before any condition negates it. In other words ! is short hand for "NOT"
Title: Permanent Watermark with GD2
Post by: Sammy on March 31, 2004, 11:27:20 am
Quote from: "Nawaf"
Hi,

i tried it but i got this error when i tried to Make the settings from control panel

Watermarking images...


I dont understand, how You get it from settings panel.
Check that You have modify right files.
Title: Permanent Watermark with GD2
Post by: uny on April 04, 2004, 09:54:32 am
hi, I just install the Newest MOD. I get the following erro

Code: [Select]
Parse error: parse error, expecting `','' or `';'' in /usr/home/ushuaren/public_html/gallery/config.php on line 297

I appreciate your help!
Title: Permanent Watermark with GD2
Post by: uny on April 04, 2004, 11:18:16 pm
Quote from: "uny"
hi, I just install the Newest MOD. I get the following erro

Code: [Select]
Parse error: parse error, expecting `','' or `';'' in /usr/home/ushuaren/public_html/gallery/config.php on line 297

I appreciate your help!


Problem fixed, but I have another two questions:

1. I just noticed that all the sudden, all the YES and NO settings in the Setting can't be chose.

I can't select Neither Yes or No.  it's all Blank.

2. If I add some new images to the album, after I upload them, is there a way to Watermark the NEW images only?

Please let me know the solution if there is any!
Thanks for your MOD!
Title: Permanent Watermark with GD2
Post by: Joachim Müller on April 04, 2004, 11:26:06 pm
you haven't applied the mod correctly. Undo all your modifications (restore the files from the original coppermine package if necessary) and re-apply the mod.

GauGau
Title: Permanent Watermark with GD2
Post by: uny on April 04, 2004, 11:31:04 pm
Quote from: "gaugau"
you haven't applied the mod correctly. Undo all your modifications (restore the files from the original coppermine package if necessary) and re-apply the mod.

GauGau


Thanks GauGau for your reply, but all I did is Upload the PHP adn SQL file that he included in the ZIP file, no Manually edit except Overwrite the file and the SQL command.

any other suggestions?

Thank you!  :)
Title: Permanent Watermark with GD2
Post by: Sammy on April 09, 2004, 02:07:26 pm
@uny

What is Your Coppermine version?
It should be newest version 1.2.1.

I have now modified 6 coppermine galleries to GD" watermarking with out any problem.

I try do that normal_ image size check to this modification on weekend.
Title: Permanent Watermark with GD2
Post by: Tarique Sani on April 10, 2004, 07:07:05 am
@Sammy - the 1.3 release is almost final now - I would suggest whatever you do now onwards should be for version 1.3
Title: Permanent Watermark with GD2
Post by: Sammy on April 10, 2004, 10:59:29 pm
@Tarique

Great to hear about 1.3 version!
I will wait for it.
Title: Permanent Watermark with GD2
Post by: photoman13 on April 11, 2004, 06:38:25 am
Sammy.. I wanna thank ya again.. your watermarking is working just great for me :):)
Title: Thanks Photoman13
Post by: Sammy on April 12, 2004, 10:36:11 pm
Quote from: "photoman13"
Sammy.. I wanna thank ya again.. your watermarking is working just great for me :):)

You're welcome!
Nice to here that it's working fine for You.
Title: Permanent Watermark with GD2
Post by: kudde6 on April 20, 2004, 07:51:38 pm
Sammy,

Does this hack also work for version 1.3.0? did you allready test that?

Regards,
K.D.
Title: Permanent Watermark with GD2
Post by: Sammy on April 21, 2004, 08:31:58 am
@kudde6

I dont know if it will work. I dont have 1.3 yet :(

Last time when I was trying to find 1.3, it was still available for those testers only. Now it seems to be available on public for a month ?  :oops:  :oops:  :oops:


I'll try it.....
Title: Re: Permanent Watermark with GD2
Post by: kudde6 on April 26, 2004, 01:03:16 pm
HI Sammy,

Any chance that you have tested it ?

Regards,
Kudde6
Title: Re: Permanent Watermark with GD2
Post by: Joachim Müller on April 26, 2004, 05:41:12 pm
why don't you test it for the community and let us know your test results ;)

GauGau
Title: Re: Permanent Watermark with GD2
Post by: darkcool on April 29, 2004, 06:09:01 pm
this was a great mod I would said.

There is something I would suggest the author of this hack or some one familiar with this hack to think into. When ever the watermark is applied the exif information in the JPEG somehow got delete. I don't know if it possible that the image to have the Exif and still have the watermark on them.


Thanks for this great mod.
Title: Re: Permanent Watermark with GD2
Post by: Burpee on April 30, 2004, 01:57:09 pm
Can you zip up the relevant files and post a link OR sent it to me

I will incorporate it into the main CPG (of course your name will be in the credits)

Do you guys plan on putting it into CPG 1.3 standard?
Would love to see that.
Permanent Watermark with GD2 + CPG 1.3 = my Dream CPG
Title: Re: Permanent Watermark with GD2
Post by: hoggwild on April 30, 2004, 04:55:08 pm
Great mod Sammy:

Does anyone have this active so that I may see the albums with the watermark?
Title: Re: Permanent Watermark with GD2
Post by: Burpee on April 30, 2004, 05:32:10 pm
Read through all posts first   :D

Sammy's site:
http://www.jarnokalliomaki.com/index_carry.shtml
Title: Re: Permanent Watermark with GD2
Post by: photoman13 on May 01, 2004, 04:51:45 am
Great mod Sammy:

Does anyone have this active so that I may see the albums with the watermark?

It's active on 2 of my sites :)

http://www.ericjon.com/photoserver

&

http://www.richiebrown.net/gallery
Title: Re: Permanent Watermark with GD2
Post by: Burpee on May 06, 2004, 01:14:42 pm
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


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:
Code: [Select]
'th_wd' => 'Width',
Add this after it
Code: [Select]
               '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:
Code: [Select]
 array('Display notices in debug mode', 'debug_notice', 1), //cpg1.3.0

Add this after it
Code: [Select]

               '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:
Code: [Select]
 'delete_orphans' => 'Delete orphaned comments (works on all albums)',
Add this a line after it
Code: [Select]
       'watermarks' => 'Add watermaks',
        '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:
Code: [Select]
$image_filesize = filesize($image);
Add this before it
Code: [Select]
      //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"
Code: [Select]
      if (file_exists($normal) && !watermark($normal))  //this is for intermediate size image


Find this:
Code: [Select]
?> (or end of picmgmt.inc.php)

Add this before it
Code: [Select]
       /**
         * 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;
            }
        }



3.
Open File util.php

Find this:
Code: [Select]
function deleteorig()
Add this before it
Code: [Select]
function vesileimaathumbit()   //watermarkthumbs
{
    global $picturetbl, $CONFIG, $lang_util_php;
    $phpself = $_SERVER['PHP_SELF'];
    $albumid = $_POST['albumid'];
    $updatetype = $_POST['updatetype'];
    $numpics = $_POST['numpics'];
    $startpic = 0;
    $startpic = $_POST['startpic'];

    $query = "SELECT * FROM $picturetbl WHERE aid = '$albumid'";
    $result = MYSQL_QUERY($query);
    $totalpics = mysql_numrows($result);

    if ($startpic == 0) {
        // 0 - numpics
        $num = $totalpics;
        // Over picture limit
        if ($totalpics > $numpics) $num = $startpic + $numpics;
    } else {
        // startpic - numpics
        $num = $startpic + $numpics;
        if ($num > $totalpics) $num = $totalpics;
    }

    $i = $startpic;
    while ($i < $num) {
        $image = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") . mysql_result($result, $i, "filename");

        if ($updatetype == 0 || $updatetype == 2) {
            $imagesize = getimagesize($image);
            if (max($imagesize[0], $imagesize[1]) > $CONFIG['picture_width'] && $CONFIG['make_intermediate'])        {
            $image = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") . $CONFIG['normal_pfx'] . mysql_result($result, $i, "filename");
                        }        else        {
            $image = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") . mysql_result($result, $i, "filename");
                        }

            if (watermark($image)) {
                print $image .' '. $lang_util_php['updated_succesfully'] . '!<br />'; //$normal .' '. $lang_util_php['updated_succesfully'] . '!<br />';
                my_flush();
            } else {
                print $lang_util_php['error_create'] . ':$image<br />'; //$lang_util_php['error_create'] . ':$normal<br />';
                my_flush();
            }
        }

        if ($updatetype == 1 || $updatetype == 2) {
            $image = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") . mysql_result($result, $i, "filename");

            if (watermark($image)) {
                print $image .' '. $lang_util_php['updated_succesfully'] . '!<br />'; //$normal .' '. $lang_util_php['updated_succesfully'] . '!<br />';
                my_flush();
            } else {
                print $lang_util_php['error_create'] . ':$image<br />'; //$lang_util_php['error_create'] . ':$normal<br />';
                my_flush();
            }
        }

        ++$i;
    }
    $startpic = $i;

    if ($startpic < $totalpics) {

        ?>
            <form action=<?php echo $phpself;
        
?>
method="post">
                    <input type="hidden" name="action" value="continuewatermarks" />
                    <input type="hidden" name="numpics" value="<?php echo $numpics?>" />
                    <input type="hidden" name="startpic" value="<?php echo $startpic?>" />
                    <input type="hidden" name="updatetype" value="<?php echo $updatetype?>" />
            <input type="hidden" name="albumid" value="<?php echo $albumid?>" />
            <input type="submit" value="<?php print $lang_util_php['continue'];
        
?>
" class="submit" /></form>
                    <?php
    
}
}  


Find this:
Code: [Select]
updatethumbs();
Add this after it
Code: [Select]

    echo '<br /><a href="' . $phpself . '">' . $lang_util_php['back'] . '</a>';
} else if ($action == 'watermarks') {//tämä
    global $picturetbl, $CONFIG;
    print '<a href="' . $phpself . '">' . $lang_util_php['back'] . '</a><br />';
    print '<h2>' . $lang_util_php['watermark_wait'] . '</h2>';

    vesileimaathumbit();  //watermarkthumbs

    echo '<br /><a href="' . $phpself . '">' . $lang_util_php['back'] . '</a>';
} else if ($action == 'continuewatermarks') {//tämä
    print '<a href="' . $phpself . '">' . $lang_util_php['back'] . '</a><br />';
    print '<h2>' . $lang_util_php['watermark_wait'] . '</h2>';

    vesileimaathumbit();  //watermarkthumbs

Find this:
Code: [Select]
starttable('100%', '<input type="radio" name="action" value="title" id="title" class="nobg"(only part of that line)

Add this before it
Code: [Select]
//This is for watermarking
    starttable('100%', '<input type="radio" name="action" value="watermarks" id="watermarks" class="nobg" /><label for="watermarks" accesskey="w" class="labelradio">' . $lang_util_php['watermarks'] . '</label> (1)');
    print '
<tr><td>
' . $lang_util_php['update_what'] . ' (2):<br />
<input type="radio" name="updatetype" value="0" id="thumb" class="nobg" /><label for="thumb" accesskey="w" class="labelradio">' . $lang_util_php['watermark_normal'] . '</label><br />
<input type="radio" name="updatetype" value="1" id="resized" class="nobg" /><label for="resized" accesskey="r" class="labelradio">' . $lang_util_php['watermark_image'] . '</label><br />
<input type="radio" name="updatetype" value="2" checked="checked" id="all" class="nobg" /><label for="all" accesskey="a" class="labelradio">' . $lang_util_php['watermark_both'] . '</label><br />
' . $lang_util_php['update_number'] . '
<input type="text" name="numpics" value="' . $defpicnum . '" size="5" /><br />
' . $lang_util_php['update_option'] . '<br /><br />
</td></tr>';
    endtable();

    print '<br />';



4.
Open file config.php

Find this:
Code: [Select]
function create_form(&$data)
Add this above it
Code: [Select]
// Added for allowing user to select where to add watermarks on pics...
function form_watermark($text, $name)
{
    global $CONFIG, $lang_config_php;

    $value = $CONFIG[$name];
    $bottomright_selected = ($value == 'bottomright') ? 'selected' : '';
    $bottomleft_selected = ($value == 'bottomleft') ? 'selected' : '';
    $topleftt_selected = ($value == 'topleftt') ? 'selected' : '';
    $topright_selected = ($value == 'topright') ? 'selected' : '';

    echo <<<EOT
        <tr>
            <td class="tableb">
                        $text
        </td>
        <td class="tableb" valign="top">
                        <select name="$name" class="listbox">
                                <option value="bottomright" $bottomright_selected>{$lang_config_php['wm_bottomright']}</option>
                                <option value="bottomleft" $bottomleft_selected>{$lang_config_php['wm_bottomleft']}</option>
                                <option value="topleftt" $topleftt_selected>{$lang_config_php['wm_topleftt']}</option>
                                <option value="topright" $topright_selected>{$lang_config_php['wm_topright']}</option>
                        </select>
                </td>
        </tr>

EOT;
}
// Added for allowing user to select which files to watermark...
function form_watermark2($text, $name)
{
    global $CONFIG, $lang_config_php;

    $value = $CONFIG[$name];
    $both_selected = ($value == 'both') ? 'selected' : '';
    $original_selected = ($value == 'original') ? 'selected' : '';
    $resized_selected = ($value == 'resized') ? 'selected' : '';

    echo <<<EOT
        <tr>
            <td class="tableb">
                        $text
        </td>
        <td class="tableb" valign="top">
                        <select name="$name" class="listbox">
                                <option value="both" $both_selected>{$lang_config_php['wm_both']}</option>
                                <option value="original" $original_selected>{$lang_config_php['wm_original']}</option>
                                <option value="resized" $resized_selected>{$lang_config_php['wm_resized']}</option>
                        </select>
                </td>
        </tr>

EOT;
}


Find this:
Code: [Select]
               case 10 :
                    form_number_dropdown($element[0], $element[1]);
                    break;

Few lines below is
Code: [Select]
die('Invalid action');
Now we need to paste this
Code: [Select]
              //Watermark place
               case 11 :
                   form_watermark($element[0], $element[1]);
                                       break;
               //Which filest to watermark
               case 12 :
                   form_watermark2($element[0], $element[1]);
                                       break;
               case 13 :
                   // do nothing
                   break;
               default:
between them.

After You have done it, it should look like this (I have put couple lines befor and after those lines in this example (hoppe You got it, becouse of My poor english :?
Code: [Select]
               // tabbed display fix
                case 10 :
                    form_number_dropdown($element[0], $element[1]);
                    break;

               //Watermark place
               case 11 :
                   form_watermark($element[0], $element[1]);
                                       break;
               //Which filest to watermark
               case 12 :
                   form_watermark2($element[0], $element[1]);
                                       break;
               case 13 :
                   // do nothing
                   break;
               default:
                    die('Invalid action');
            } // switch
        } else {
            form_label($element);


5.
Then You need to execute theese SQL commands with phpMyAdmin or Webmin, etc.

Code: [Select]
insert into cpg11d_config (name, value) values ('enable_watermark', '1');
insert into cpg11d_config (name, value) values ('where_put_watermark', 'bottomright');
insert into cpg11d_config (name, value) values ('watermark_file', '/your/full/path/to/logo.png');
insert into cpg11d_config (name, value) values ('which_files_to_watermark', 'both');


Thats it. Now You can go to settings and set it up.
Actually You need to go there, before trying to add new pics.
You have to change 'Which file to use for watermark' to point to your own logo.png file that is used as watermark.


This should contain every modification I have made.
Title: Re: Permanent Watermark with GD2
Post by: Tarique Sani on May 06, 2004, 01:20:57 pm
And a zip file with the mod is located at? :D

Great work - thanks
Title: Re: Permanent Watermark with GD2
Post by: Sammy on May 06, 2004, 01:49:46 pm
 ;D Great Job Guys !

I have been busy at my day job for a few weeks now and have'nt done that 1.3 mod yet, so thanks!
Title: Re: Permanent Watermark with GD2
Post by: Burpee on May 06, 2004, 08:00:09 pm
And a zip file with the mod is located at? :D

Great work - thanks

It doesn't look like that'll be happening for a while...
Some strange bug in Windows XP in combination with an ATI Radeon is causing me to be unable to write to my disk... so that has a higher priority right now...
*deep sigh*
I HATE Micro$oft
Title: Re: Permanent Watermark with GD2
Post by: bloodynipples on May 09, 2004, 03:06:22 am
I have a prob.

I applied the zip'ed files to my coppermine directory and verified that they are correct accoring to your how-to post.

I am getting the follwing error: 

Quote
Fatal error: Call to undefined function: watermark() in /home/brewcomm/public_html/coppermine/util.php on line 243

anyone have any ideas?
Title: Re: Permanent Watermark with GD2
Post by: Joachim Müller on May 09, 2004, 08:43:13 am
you probably haven't applied the hack properly. Undo your modifications (replace with clean coppermine files) and start from scratch. There's nothing else that can be done...

GauGau
Title: Re: Permanent Watermark with GD2
Post by: trampy on May 09, 2004, 06:11:22 pm
Someone have this working under CPG_Nuke 1.2.2b ?

Title: Re: Permanent Watermark with GD2
Post by: Joachim Müller on May 09, 2004, 06:50:58 pm
better check the nuke support board (http://www.nukephotogallery.com/modules.php?name=Forums) for this...

GauGau
Title: Re: Permanent Watermark with GD2
Post by: alsaher on May 27, 2004, 02:51:06 pm
hi

when i try  to upload  the  pic   this  error  msg  come

Code: [Select]
The picture 'albums/userpics/10001/041.jpg' can't be inserted in the album





Warning: imagecreatefrompng(http://www.alsaher.net/photo/include/logo.png): failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in /home/alsaher/public_html/photo/include/picmgmt.inc.php on line 274

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

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

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

Warning: getimagesize(albums/userpics/10001/normal_041.jpg): failed to open stream: No such file or directory in /home/alsaher/public_html/photo/include/picmgmt.inc.php on line 231



Title: Re: Permanent Watermark with GD2
Post by: bloodynipples on June 08, 2004, 06:47:08 am
Hi,

i tried it but i got this error when i tried to Make the settings from control panel

Watermarking images...

Warning: imagesx(): supplied argument is not a valid Image resource in /home/content/d/o/c/docarabiacom/html/cpg/include/picmgmt.inc.php on line 275

Warning: imagesy(): supplied argument is not a valid Image resource in /home/content/d/o/c/docarabiacom/html/cpg/include/picmgmt.inc.php on line 276

Warning: imagecopy(): supplied argument is not a valid Image resource in /home/content/d/o/c/docarabiacom/html/cpg/include/picmgmt.inc.php on line 293
albums/userpics/infarct.jpg updated succesfully!

Warning: imagesx(): supplied argument is not a valid Image resource in /home/content/d/o/c/docarabiacom/html/cpg/include/picmgmt.inc.php on line 275

Warning: imagesy(): supplied argument is not a valid Image resource in /home/content/d/o/c/docarabiacom/html/cpg/include/picmgmt.inc.php on line 276

Warning: imagecopy(): supplied argument is not a valid Image resource in /home/content/d/o/c/docarabiacom/html/cpg/include/picmgmt.inc.php on line 293
albums/userpics/infarct.jpg updated succesfully!

Warning: imagesx(): supplied argument is not a valid Image resource in /home/content/d/o/c/docarabiacom/html/cpg/include/picmgmt.inc.php on line 275

Warning: imagesy(): supplied argument is not a valid Image resource in /home/content/d/o/c/docarabiacom/html/cpg/include/picmgmt.inc.php on line 276

Warning: imagecopy(): supplied argument is not a valid Image resource in /home/content/d/o/c/docarabiacom/html/cpg/include/picmgmt.inc.php on line 293
albums/userpics/art_normal.jpg updated succesfully!

Warning: imagesx(): supplied argument is not a valid Image resource in /home/content/d/o/c/docarabiacom/html/cpg/include/picmgmt.inc.php on line 275

Warning: imagesy(): supplied argument is not a valid Image resource in /home/content/d/o/c/docarabiacom/html/cpg/include/picmgmt.inc.php on line 276

Warning: imagecopy(): supplied argument is not a valid Image resource in /home/content/d/o/c/docarabiacom/html/cpg/include/picmgmt.inc.php on line 293
albums/userpics/art_normal.jpg updated succesfully!

I had the same problem, and solved it.

The problem was the database.  You must make sure the database changes were made, in my case I had installed a second version of coppermine with the table prefix cpg11_  not cpg11d_
Title: Re: Permanent Watermark with GD2
Post by: snork13 on June 09, 2004, 06:11:40 am
Thanks to all, got it working great!!! :P

snork13.net
Title: Re: Permanent Watermark with GD2
Post by: turtleboy on June 13, 2004, 09:22:37 am
Got these errors while running Burpee's latest mod after I applied the watermark with util.php (using 1.3.0):

Warning: imagejpeg(): Unable to open 'albums/familymiscbatch1/mamupops1.jpg' for writing in /home/content/t/u/r/turtleboy212/html/foto/foto-gallery/include/picmgmt.inc.php on line 317
albums/familymiscbatch1/mamupops1.jpg updated succesfully!
albums/userpics/puffpuff.jpg updated succesfully!
ERROR creating:$image

It seems to apply it to some and not others. And it returns multiple identical returns when it's finished like this:
albums/userpics/puffpuff.jpg updated succesfully!
albums/userpics/puffpuff.jpg updated succesfully!

heres the files i am using:
http://www.skylinedesigns.net/misc/gd2watermark.rar
Title: Re: Permanent Watermark with GD2
Post by: m0nty on June 19, 2004, 03:09:08 pm
i've applied this mod to my 1.3 installation and everything worked perfectly.. excellent mod and thanks to the author..

however i think you should make it more clear for beginners in the instructions regarding the final mysql settings..

in particular:

insert into cpg11d_config (name, value) values ('enable_watermark', '1');
insert into cpg11d_config (name, value) values ('where_put_watermark', 'bottomright');
insert into cpg11d_config (name, value) values ('watermark_file', '/*******/**/*********/htdocs/gallery/watermark.png');
insert into cpg11d_config (name, value) values ('which_files_to_watermark', 'both');

the prefix highlighted in red should be made clearer that the user needs to edit this and make sure it corresponds to their gallery prefix.. ie my gallery prefix is cihgallery_

and the path to the watermark image highlighted in blue should be made clear that this has to be the full directory path and not a URL

experienced users will know this already, but the less experienced may not realise..

regards

Vaughan





Title: Re: [CPG1.2.1]: Permanent Watermark with GD2
Post by: khayman on June 22, 2004, 10:33:23 pm
First off - I must saw, awesome mod!

Two things:

1) Is it possible to adjust the transparency of the watermark, or is that something that needs to be done with the watermark itself (i.e. use a transparent png file).

2) Has anyone worked on code to center the watermark and place it on the original image and then do resizing, while storing an UNwatermarked image? If so I'd like a peek, if not I'll try and hack away at them and post the code.

Cheers,
~jb

Title: Re: [CPG1.2.1]: Permanent Watermark with GD2
Post by: Burpee on June 23, 2004, 12:50:14 am
First off - I must saw, awesome mod!

Two things:

1) Is it possible to adjust the transparency of the watermark, or is that something that needs to be done with the watermark itself (i.e. use a transparent png file).

2) Has anyone worked on code to center the watermark and place it on the original image and then do resizing, while storing an UNwatermarked image? If so I'd like a peek, if not I'll try and hack away at them and post the code.

Cheers,
~jb



1) It's in the PNG :D
2) I followed everything you were saying until you said "storing an UNwatermarked image" ... why would you want to watermark it and then store an image w/o watermark?
Anyway, nope, nobody has tried that for afaik... I don't think the code is that hard though, you'd just have to do some math for centering the watermark... if you figure it out, post it here :D
Title: Re: [CPG1.2.1]: Permanent Watermark with GD2
Post by: khayman on June 23, 2004, 05:34:27 am
Burpee,

The reason for storing an UNwatermarked original is because of the type of site I want to set up - eventually I want people to be able to order prints from it. If the original and the resized images are watermarked, then I have nothing to make a print off of. I was looking at things and I believe what I will do is just watermark the resized and have that as the main image with no click on for a full size image :) some of them get pretty large!

Thanks for the response!
Title: Re: [CPG1.2.1]: Permanent Watermark with GD2
Post by: Burpee on June 23, 2004, 09:44:51 am
Wouldn't you want to store the printing formats locally on your computer anyway?
And if you'd really want people to order prints, you should have fairly low res images on your site.
Title: Re: [CPG1.2.1]: Permanent Watermark with GD2
Post by: Joachim Müller on June 23, 2004, 10:17:28 am
I agree with Burpee: if you keep the hires pics on the server, anybody who knows the naming scheme of coppermine could get the hires pics for free by just entering the url.

GauGau
Title: Re: [CPG1.2.1]: Permanent Watermark with GD2
Post by: DaMysterious on June 23, 2004, 11:55:15 am
Cool! Thanks for this MOD. Just installed and it seems to work perfectly (http://damysterious.xs4all.nl/gallery/displayimage.php?album=lastup&cat=&pos=0) hier in all modes 8). I have to change the .png now.
Title: Re: [CPG1.2.1]: Permanent Watermark with GD2
Post by: khayman on June 23, 2004, 06:40:29 pm
Burpee/GauGau,

Yeah I realized that regarding the image path... going to have to rethink my strategy. One thing I could do is a daily check on when images are uploaded and manually move those images to my local drive. I won't have all the photos initially as some of them will be coming from other people posting their images as well. I figure it's best to get the hi-res versions when the user uploads it instead of having to contact them if/when someone wants to purchase a print.
Title: Re: [CPG1.2.1]: Permanent Watermark with GD2
Post by: maria on October 15, 2004, 10:37:53 pm
I need obtain that watermark is added to the photos that I raise with of the batch, they excuse if I am annoying but I am new in this forum and I need do this for my CPG. Thanks
 ::)
Title: Re: [CPG1.2.1]: Permanent Watermark with GD2
Post by: Joachim Müller on October 16, 2004, 08:36:59 am
thze mod does what it says, not more. You shouldn't request new features, especially for a mod that was written for an outdated version (cpg1.2.1).

Joachim
Title: Re: [CPG1.2.1]: Permanent Watermark with GD2
Post by: maria on October 16, 2004, 07:09:37 pm
Jachim thanks for your answer already I have post again in post of the version 1.3.x
Bye !
Maria
Title: Re: Permanent Watermark with GD2
Post by: n3n on December 13, 2004, 01:22:26 pm
Tnx for the mod, works really great, although i have one problem.
At first i didnt see it was for version 1.2, but i didnt care when i saw it, cause it worked, but now i noticed that my
crop and rotate buttons and edit picture buttons are gone.. Does anyone have a solution ?

tnx in advance
Title: Re: Permanent Watermark with GD2
Post by: Nibbler on December 13, 2004, 01:45:24 pm
Apply the correct version maybe.
Title: Re: Permanent Watermark with GD2
Post by: n3n on December 13, 2004, 02:48:07 pm
actually i used the zip, and copied the files, and the index.php head said it was the correct version. Didnt anybody else have this problem ?
Title: Watermark with cpgnuke ? How ?
Post by: kleppen on December 18, 2004, 01:42:03 am
Hello..
I am using cpgnuke at my homepage and now I wonder if it´s a watermark hack for
cpgnuke or if some one can help me to write the code I need.
I have looked in the forums but the watermark hacks are just for coppermine stand alone version.
Please can some one help me..
I really need that hack
tanx
david

PS
My php is not good
ds
Title: Re: Permanent Watermark with GD2
Post by: Tranz on December 18, 2004, 02:37:47 am
Why don't you ask for help at http://cpgnuke.com? They have forums too.
Title: Re: Permanent Watermark with GD2
Post by: Casper on December 18, 2004, 11:29:55 am
Or do what we suggest is best, and watermark them on your client before upload, using a free batch watermarking tool like this (http://www.faststoneserver.com/FSResizerDetail.htm)
Title: Re: Permanent Watermark with GD2
Post by: opulence on February 20, 2005, 03:19:49 am
I'd like to use Burpee's mod of this mod, for CPG 1.3... however I'm wondering where the watermark will appear?  and how to set it so that it will appear at bottom - 10px left - 10px  (in the bottom left corner with a 10 pixel offset).
Title: Re: Permanent Watermark with GD2
Post by: davidshook on February 24, 2005, 05:01:12 am
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
Title: Re: Permanent Watermark with GD2
Post by: kegobeer on February 24, 2005, 06:06:17 am
David, don't post identical replies in two different threads.  If you are using 1.2, post here.  If you are using 1.3, post in the other thread.
Title: Re: Permanent Watermark with GD2
Post by: thejinx0r on March 03, 2005, 06:46:56 pm
I am getting
Code: [Select]
Parse error: parse error, unexpected ';' in /usr/home/sirjinx/public_html/RSP/util.php on line 279
This is what is on line 279
Code: [Select]
        ?>" class="submit" /></form>
But I am also a noob when it comes to modifications.
For step 2, I didnt understand what you ment by
Quote
Activate all after above code and paste all from below
What do you mean by "activate" ?

(I've attached the files in case you might want too look at it.)
Title: Re: Permanent Watermark with GD2
Post by: Tranz on March 03, 2005, 06:54:23 pm
Try changing
Code: [Select]
        ?>" class="submit" /></form>to
Code: [Select]
?>
" class="submit" /></form>
Title: Re: Permanent Watermark with GD2
Post by: thejinx0r on March 03, 2005, 08:54:28 pm
Try changing
Code: [Select]
        ?>" class="submit" /></form>to
Code: [Select]
?>
" class="submit" /></form>

ok i've tried
stills says the error on line 279. so problem has to be coming from ?>
but I'm not very good in php. I've tried moving it around. Making it /> or just >
Title: Re: Permanent Watermark with GD2
Post by: Tranz on March 03, 2005, 08:57:04 pm
When I opened the file you included in your post, it included lots of extra lines. So line 279 isn't what you posted. You probably have issues elsewhere. I would suggest starting over. Sorry.
Title: Re: Permanent Watermark with GD2
Post by: kegobeer on March 03, 2005, 09:04:39 pm
I think your problem is in this line:

<input type="submit" value="<?php print $lang_util_php&#91;'continue'&#93;;

Try this

Code: [Select]
<input type="submit" value="<?php print $lang_util_php['continue']
When you copy and paste, make sure you are using notepad or something like it.  Frontpage and other crappy tools like it will change certain characters to the ascii number, which screws up your code.

That's in util.php.  Sorry I didn't mention at the start of this post.
Title: Re: Permanent Watermark with GD2
Post by: thejinx0r on March 03, 2005, 09:11:55 pm
k nvm.
im too much of a noob.
installed the wrong version...
sry :(

i have 1.3.2
and this 1.2.x =/
Title: Re: Permanent Watermark with GD2
Post by: TopShelfExotics on May 11, 2005, 08:32:45 pm
Is there any easy way to watermark existing photos to match the way the new modification watermarks new uploads?!

I'd like to watermark all of the existing photos in our gallieries to match but dont want to have to re-upload everything and ask our members to do the same. Any advise would be appreciated. I would also like to thank everyone for the informatitive posts, I installed the mod in about eight minutes with no issue whatsoever. Thank you.

Our Gallery:

http://topshelfexotic.com/gallery/
Title: Re: Permanent Watermark with GD2
Post by: poubao on May 11, 2005, 10:25:06 pm
in admin mod, go in util, and select "watermark", and watermark your existing photos in your gallery.
poubao :D
Title: Re: Permanent Watermark with GD2
Post by: undeshila on February 20, 2006, 12:34:09 pm
hey all

first i wana thank for this great mod


ive installed it before and had no problems , but now on another gallery im having difficulties

when i wanna upload a new picture , it uploads fine but when i want to assign it to an album , it says Warning: getimagesize(albums/userpics/10001/normal_test.jpg): failed to open stream: No such file or directory in /****/include/picmgmt.inc.php on line 231


Line 231 is - 
Code: [Select]
$imginfo = getimagesize($src_file);


Ive modified the picmgmt.inc.php  myself and also put the file included in the .zip by sammy , and the same thing ...

The files added before get watermarked , but now i cant even upload new pics , not to mention upload + watermark automatically
What could be the problem ?

And also , if u could help with one question , how to batch the entire gallery , not every album separately , there are 2000+ albums
Title: Re: Permanent Watermark with GD2
Post by: Sammy on February 20, 2006, 12:46:02 pm
Hi

what coppermine version You are using?
This mod is for 1.2.1.

1.3 version is available also, You can obtain it from different location.
It's made by BurBee and U can find it in same category as this topic.
Title: Re: Permanent Watermark with GD2
Post by: Sammy on February 20, 2006, 12:47:50 pm
Here's link to BurBee's 1.3 version ;)

http://forum.coppermine-gallery.net/index.php?topic=7160.0
Title: Re: Permanent Watermark with GD2
Post by: undeshila on February 20, 2006, 01:48:39 pm
well i knew it was made by you and hence ive modified with this one :( and now its *&!^$#*@#*&$#@


do u happen to have 1.3.2 files that are modified ? can u make a zip pls ? :) with the original files so that i can modify them accordingly to 1.3 modifs or if u have a zip with the files already modified like here but for the 1.3
Title: Re: Permanent Watermark with GD2
Post by: undeshila on February 20, 2006, 02:21:26 pm
disregard , ive got the original files and modified accordingly to 1.3 and everything is OK now :) tnx again for the mod and for the attention