Add this code to your theme’s functions.php file
, and it will limit minimum image dimentions:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | add_filter('wp_handle_upload_prefilter','tc_handle_upload_prefilter'); function tc_handle_upload_prefilter($file) { $img=getimagesize($file['tmp_name']); $minimum = array('width' => '640', 'height' => '480'); $width= $img[0]; $height =$img[1]; if ($width < $minimum['width'] ) return array("error"=>"Image dimensions are too small. Minimum width is {$minimum['width']}px. Uploaded image width is $width px"); elseif ($height < $minimum['height']) return array("error"=>"Image dimensions are too small. Minimum height is {$minimum['height']}px. Uploaded image height is $height px"); else return $file; } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.