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: Limiting Pixel Width and Height during Upload  (Read 2883 times)

0 Members and 1 Guest are viewing this topic.

GarryS

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 22
Limiting Pixel Width and Height during Upload
« 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.
Logged

Jeff Bailey

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: us
  • Offline Offline
  • Gender: Male
  • Posts: 1322
  • Fishing relaxes me.
    • Bailey Family Co.
Logged
Thinking is the hardest work there is, which is probably the reason why so few engage in it. - Henry Ford

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: Limiting Pixel Width and Height during Upload
« Reply #2 on: September 11, 2012, 09:51:11 am »

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
Code: [Select]
        // 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.

Code: [Select]
        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);
        }
Logged

GarryS

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 22
Re: Limiting Pixel Width and Height during Upload
« Reply #3 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.
Logged
Pages: [1]   Go Up
 

Page created in 0.021 seconds with 20 queries.