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