Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
* Plugin Name: Deny Giant Image Uploads
* Description: Prevents Uploads of images greater than 3.2MP
* Author: TJNowell
* Author URI:
* Plugin URI:
* Version: 1.1
function tomjn_deny_giant_images($file){
$type = explode('/',$file['type']);
if($type[0] == 'image'){
list( $width, $height, $imagetype, $hwstring, $mime, $rgb_r_cmyk, $bit ) = getimagesize( $file['tmp_name'] );
if($width * $height > 3200728){ // I added 100,000 as sometimes there are more rows/columns than visible pixels depending on the format
$file['error'] = 'This image is too large, resize it prior to uploading, ideally below 3.2MP or 2048x1536';
return $file;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment