Thread: Business Wordpress help please!
View Single Post
Old 04-15-2017, 10:45 AM  
fris
Too lazy to set a custom title
 
fris's Avatar
 
Industry Role:
Join Date: Aug 2002
Posts: 55,289
here is both methods

Code:
add_filter('wp_handle_upload_prefilter','_limit_image_dimensions');

function _limit_image_dimensions( $file ) {
    $image = getimagesize($file['tmp_name']);

    $minimum = array(
        'width' => '400',
        'height' => '400'
    );

    $maximum = array(
        'width' => '2000',
        'height' => '2000'
    );
    $image_width = $image[0];
    $image_height = $image[1];

    $too_small = "Image dimensions are too small. Minimum size is {$minimum['width']} by {$minimum['height']} pixels. Uploaded image is $image_width by $image_height pixels.";
    $too_large = "Image dimensions are too large. Maximum size is {$maximum['width']} by {$maximum['height']} pixels. Uploaded image is $image_width by $image_height pixels.";

    if ( $image_width < $minimum['width'] || $image_height < $minimum['height'] ) {
        $file['error'] = $too_small; 
        return $file;
    }
    elseif ( $image_width > $maximum['width'] || $image_height > $maximum['height'] ) {
        $file['error'] = $too_large; 
        return $file;
    }
    else
        return $file;
}

function _limit_image_size($file) {

    $image_size = $file['size']/1024;

    $limit = 200; // size in kb

    $is_image = strpos($file['type'], 'image');

    if ( ( $image_size > $limit ) && ($is_image !== false) )
          $file['error'] = 'Your picture is too large. It has to be smaller than '. $limit .'KB';

          return $file;

}
add_filter('wp_handle_upload_prefilter', '_limit_image_size');
__________________
Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.


WP Stuff
fris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote