Banner Logo

Be a part of the family: Connect, Receive Support,
Contribute, and Reap Abundant Rewards!

Product Image size restriction

When someone uploading an images how can we manage that they are not to big, it is possible to downsize those to lets say 500×500 automatically?

>> There is no automated solution for this. However using the below code you can add restriction on this :

function resize_resolution($file) {
$image = getimagesize($file['tmp_name']);
    $minimum = array(
        'width' => '400',   //set your minimum
        'height' => '400'
    );
    $maximum = array(
        'width' => '2000',  //set your maximum
        'height' => '2000'
    );
    $image_width = $image[0];
    $image_height = $image[1];

    $too_small = "Image dimensions are too small.";
    $too_large = "Image dimensions are too large.";

    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;
}
add_filter('wp_handle_upload_prefilter', 'resize_resolution');

Leave a Reply