Limiting Pixel Width and Height during Upload Limiting Pixel Width and Height during Upload
 

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

Limiting Pixel Width and Height during Upload

Started by GarryS, September 10, 2012, 09:21:40 PM

Previous topic - Next topic

0 Members and 3 Guests are viewing this topic.

GarryS

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.

Jeff Bailey

Thinking is the hardest work there is, which is probably the reason why so few engage in it. - Henry Ford

ΑndrĂ©

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

GarryS

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.