Adding a minimum/maximum image upload size?

Good evening fellow Hivepressers!

I have been reading a lot of comments regarding other users having difficulty maintaining some consistency with the size of their listings, and a lot of this is to do with the image size that is being uploaded.

I understand that you can set cropping options, which now only seems to leave an issue for images being uploaded which are too small.

Has anyone experimented with putting restrictions on image uploads, for example, the image height must be at least 400px? and/or image must be less than 2mb.

I’ve had a look around the internet and found some similar code.
Would this be easy to manipulate to fit hivepress?

 * Plugin Name: Deny Giant Image Uploads
 * Description: Prevents Uploads of images greater than 3.2MP

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;

If anyone has had any success with this, please share.

Thanks in advance.


Unfortunately, there’s no way to restrict this with a filter, but you can adjust the media settings, and any larger image will be cropped automatically How to customize the image sizes - HivePress Help Center. You can also limit the maximum upload file size How to Increase Maximum File Upload Size in WordPress

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.