Advanced search  

News:

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

Pages: [1]   Go Down

Author Topic: different watermarks on different size pictures  (Read 3408 times)

0 Members and 1 Guest are viewing this topic.

karolyte

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 24
different watermarks on different size pictures
« on: September 12, 2011, 12:55:17 pm »

Hi. I would like to know how can i put different watermarks on different size of photos. I'd like normal photos to have one watermark, and original size photos other. For example: http://demipictures.com/displayimage.php?album=1236&pid=123462#top_display_media
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: different watermarks on different size pictures
« Reply #1 on: September 12, 2011, 02:45:05 pm »

You'd need to modify the function resize_image in include/picmgmt.inc.php. Depending on your settings (IM/GD1/GD2) you have to edit different code parts.
Logged

karolyte

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 24
Re: different watermarks on different size pictures
« Reply #2 on: September 12, 2011, 02:51:50 pm »

Mine is GD2, so can you tell me which codes I need to modify?
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: different watermarks on different size pictures
« Reply #3 on: September 12, 2011, 03:10:05 pm »

Find
Code: [Select]
case "gd2" :and below, add something like
Code: [Select]
            $path_parts = pathinfo($dest_file);
            if (strpos($path_parts['filename'], $CONFIG['normal_pfx']) === 0) {
                $CONFIG['watermark_file'] = 'images/watermark_normal.png';
            }
(not tested).
Logged

karolyte

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 24
Re: different watermarks on different size pictures
« Reply #4 on: September 12, 2011, 03:19:17 pm »

I'm afraid it doesn't work. It still gives me the same watermarks on both photos.
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: different watermarks on different size pictures
« Reply #5 on: September 12, 2011, 03:28:18 pm »

Just to make sure, you uploaded a new picture after you applied the mod?
Logged

karolyte

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 24
Re: different watermarks on different size pictures
« Reply #6 on: September 12, 2011, 03:34:35 pm »

Yes, I did.
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: different watermarks on different size pictures
« Reply #7 on: September 12, 2011, 03:58:05 pm »

Please replace everything from
Code: [Select]
case "gd2" :to
Code: [Select]
break;with
Code: [Select]
        case "gd2" :
            if (!function_exists('imagecreatefromjpeg')) {
                return array('error' => 'PHP running on your server does not support the GD image library, check with your webhost if ImageMagick is installed', 'halt_upload' => 1);
            }
            if (!function_exists('imagecreatetruecolor')) {
                return array('error' => 'PHP running on your server does not support GD version 2.x, please switch to GD version 1.x on the admin page', 'halt_upload' => 1);
            }
            if ($imginfo[2] == GIS_GIF && $CONFIG['GIF_support'] == 1)
                $src_img = imagecreatefromgif($src_file);
            elseif ($imginfo[2] == GIS_JPG)
                $src_img = imagecreatefromjpeg($src_file);
            elseif ($imginfo[2] == GIS_PNG)
                $src_img = imagecreatefrompng($src_file);
            else {
                include_once('classPhpPsdReader.php');
                $src_img = imagecreatefrompsd($src_file);
            }
            if (!$src_img) {
                $ERROR = $lang_errors['invalid_image'];
                //return false;
                return array('error' => $ERROR);
            }
            if ($imginfo[2] == GIS_GIF) {
                $dst_img = imagecreate($destWidth, $destHeight);
            } else {
                $dst_img = imagecreatetruecolor($destWidth, $destHeight);
                if ($imginfo[2] == GIS_PNG) {
                    imagealphablending($dst_img, false);
                }
            }
            imagecopyresampled($dst_img, $src_img, 0, 0, $xOffset, $yOffset, (int)$destWidth, (int)$destHeight, $srcWidth, $srcHeight);
            touch($dest_file);
            $fh=fopen($dest_file,'w');
            fclose($fh);

            //sharpen the thumb
            if ($sharpen==1 && $CONFIG['enable_unsharp']==1) {
                UnsharpMask($dst_img, $CONFIG['unsharp_amount'], $CONFIG['unsharp_radius'], $CONFIG['unsharp_threshold']);
            }

            if ($media_type != "false") {
                //if a manual thumb gets generated we watermark the thumb with the media type
                //we now need to get the absolute path to the thumb watermark files
                $path_parts = pathinfo($CONFIG['watermark_file']);
                $CONFIG['watermark_file'] = $path_parts["dirname"]."/wm_".$media_type.".png";
            }

            $path_parts = pathinfo($dest_file);
            if (strpos($path_parts['filename'], $CONFIG['normal_pfx']) === 0) {
                $watermark_file = 'images/watermark_normal.png';
            } else {
                $watermark_file = $CONFIG['watermark_file'];
            }

            if ($watermark == "true" || $media_type != "false") {
                //shrink watermark on intermediate images -> If I had known that this is that �%&# with the transparency preserve... grrr
                $wm_normal = (int)$CONFIG['reduce_watermark'];
                if ($wm_normal > $destWidth ) {
                    $wm_resize = $destWidth / $wm_normal;
                    //load the original, huge sized logo (the one we want to size down)
                    $temp_logoImage = ImageCreateFromPNG($watermark_file);
                    //get it's size
                    $temp_logoW = ImageSX($temp_logoImage);
                    $temp_logoH = ImageSY($temp_logoImage);

                    //calculate new size
                    $logoW = (int)($temp_logoW * $wm_resize);
                    $logoH = (int)($temp_logoH * $wm_resize);
                    //we create a new, resized logo
                    $logoImage = imagecreatetruecolor($logoW, $logoH);

                    //just to be sure that transparency gets preserved
                    imagealphablending($logoImage, FALSE);
                    imagealphablending($temp_logoImage, TRUE);

                    //now copy and resize the big one into the temp resized img
                    imagecopyresampled($logoImage, $temp_logoImage, 0, 0, 0, 0, (int)$logoW, (int)$logoH, $temp_logoW, $temp_logoH);

                    //we do not need the temp (huge) watermark anymore
                    imagedestroy($temp_logoImage);

                } else { // shrink not enabled or no intermediate...
                    $logoImage = ImageCreateFromPNG($watermark_file);
                    $logoW = ImageSX($logoImage);
                    $logoH = ImageSY($logoImage);
                }

                //where is the watermark displayed...
                $pos = $CONFIG['where_put_watermark'];
                if ($pos == "northwest") {
                    $src_x = 5;
                    $src_y = 5;
                } else if ($pos == "northeast") {
                    $src_x = $destWidth - ($logoW + 5);
                    $src_y = 5;
                } else if ($pos == "southwest") {
                    $src_x = 5;
                    $src_y = $destHeight - ($logoH + 5);
                } else if ($pos == "southeast") {
                    $src_x = $destWidth - ($logoW + 5);
                    $src_y = $destHeight - ($logoH + 5);
                } else if ($pos == "center") {
                    $src_x = ($destWidth/2) - ($logoW/2);
                    $src_y = ($destHeight/2) - ($logoH/2);
                }

                imagealphablending($dst_img, TRUE);
                imagecolortransparent($logoImage, imagecolorat($logoImage, $CONFIG['watermark_transparency_featherx'], $CONFIG['watermark_transparency_feathery']));
                ImageCopy($dst_img,$logoImage,$src_x,$src_y,0,0,$logoW,$logoH);
            }

            if ($imginfo[2] == GIS_PNG) {
                imagesavealpha($dst_img, true);
                imagepng($dst_img, $dest_file, round((100 - $CONFIG['jpeg_qual']) / 10));
            } else {
                imagejpeg($dst_img, $dest_file, $CONFIG['jpeg_qual']);
            }
            imagedestroy($src_img);
            imagedestroy($dst_img);
            break;
Logged

karolyte

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 24
Re: different watermarks on different size pictures
« Reply #8 on: September 12, 2011, 04:02:43 pm »

It works perfectly. Thank you!
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: different watermarks on different size pictures
« Reply #9 on: September 12, 2011, 04:19:02 pm »

you can tag your answer as "solved" by clicking on the "Topic Solved" button on the bar at the left hand side at the bottom of your thread.
Logged
Pages: [1]   Go Up
 

Page created in 0.031 seconds with 20 queries.