coppermine-gallery.com/forum

Support => cpg1.5.x Support => cpg1.5 miscellaneous => Topic started by: GarryS on September 10, 2012, 09:21:40 PM

Title: Limiting Pixel Width and Height during Upload
Post by: GarryS on September 10, 2012, 09:21:40 PM
My site URL is: http://www.victoriacameraclub.org/vcccompetitions/

Our club has established a new competitions gallery using Coppermine, as above. Our pixel limits for entered images is 1400 pixels wide AND 1050 pixels high.

The gallery configuration sets only the 1400 x 1400 pixel box as a limit, leaving Competitions Admin to 'police' the vertical dimension.

Is there any simple coding that could be used to set a test on each of the width and height and to disable the upload if either exceed its own separate limit?

Thank you for any help you may be able to offer on this item.
Title: Re: Limiting Pixel Width and Height during Upload
Post by: Jeff Bailey on September 10, 2012, 09:33:03 PM
Have you tried using:
http://documentation.coppermine-gallery.net/en/configuration.htm#admin_picture_thumbnail_intermediate_use-dimension

So something the like, set the max size like you have:
http://documentation.coppermine-gallery.net/en/configuration.htm#admin_picture_thumbnail_max_upload_size

Then set a resize for the height with:
http://documentation.coppermine-gallery.net/en/configuration.htm#admin_picture_thumbnail_intermediate_use-dimension
Title: Re: Limiting Pixel Width and Height during Upload
Post by: ΑndrĂ© on September 11, 2012, 09:51:11 AM
Quote from: GarryS on September 10, 2012, 09:21:40 PM
Is there any simple coding that could be used to set a test on each of the width and height and to disable the upload if either exceed its own separate limit?

Open include/picmgmt.inc.php and find
        // resize picture if it's bigger than the max width or height for uploaded pictures
        if (max($imagesize[0], $imagesize[1]) > $CONFIG['max_upl_width_height']) {
            if ((USER_IS_ADMIN && $CONFIG['auto_resize'] == 1) || (!USER_IS_ADMIN && $CONFIG['auto_resize'] > 0)) {
                $resize_method = $CONFIG['picture_use'] == "thumb" ? ($CONFIG['thumb_use'] == "ex" ? "any" : $CONFIG['thumb_use']) : $CONFIG['picture_use'];
                resize_image($image, $image, $CONFIG['max_upl_width_height'], $CONFIG['thumb_method'], $resize_method, 'false');
                $imagesize = cpg_getimagesize($image);
            } elseif (USER_IS_ADMIN) {
                // skip resizing for admin
                $picture_original_size = true;
            } else {
                @unlink($uploaded_pic);
                $msg = sprintf($lang_db_input_php['err_fsize_too_large'], $CONFIG['max_upl_width_height'], $CONFIG['max_upl_width_height']);
                return array('error' => $msg, 'halt_upload' => 1);
            }
        }


If you want to reject each picture that exceeds that limit even before Coppermine tries to resize it (if enabled in config), add the following code before the above mentioned code block. If you want to check the image's size after Coppermine resized it, add it after the above mentioned code block.

        if ($imagesize[0] > 1400 || $imagesize[1] > 1050) {
            @unlink($uploaded_pic);
            $msg = sprintf($lang_db_input_php['err_fsize_too_large'], $CONFIG['max_upl_width_height'], $CONFIG['max_upl_width_height']);
            return array('error' => $msg, 'halt_upload' => 1);
        }
Title: Re: Limiting Pixel Width and Height during Upload
Post by: GarryS on September 11, 2012, 05:32:30 PM
Perfect! That is exactly what we were hoping for. I placed the code before the resize block to prevent an upload if either the width or height criteria were exceeded. Our goal is to have the member correctly size their images prior to entering the competition.

I did, in the lang file, alter the error message to read, 'The size of file you have uploaded is too large (maximum allowed is 1400 x 1050 pixels)!'

Thank you very much, Andre. Our camera club members are favourably impressed by this new software for managing our competitions.