different watermarks on different size pictures different watermarks on different size pictures
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

different watermarks on different size pictures

Started by karolyte, September 12, 2011, 12:55:17 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

karolyte

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

Αndré

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.

karolyte

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

Αndré

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

(not tested).

karolyte

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

Αndré

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


Αndré

Please replace everything from
case "gd2" :
to
break;
with
        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;

karolyte


Αndré

Quote from: Joachim Müller on September 28, 2008, 12:46:26 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.