Minimum Image Width and Height
-
Hello.
Great plugin.
I am pro user but posting here because it may help the others as well.Basically, I would like to have minimum width and height restriction for the uploaded images from the frontend panel.
Currently, the Prefilter script I am using, which is wordpress core function, allows me to execute limit to backend upload only.
On the frontend I am getting javascript Undefined notification.Can you tell me if it is possible to achieve it using this plugin or how to modify the code I am using to get the wanted results?
The code is:
add_action( ‘admin_init’, ‘block_authors_from_uploading_small_images’ );function block_authors_from_uploading_small_images()
{
if( !current_user_can( ‘administrator’) )
add_filter( ‘wp_handle_upload_prefilter’, ‘block_small_images_upload’ );
}function block_small_images_upload( $file )
{
// Mime type with dimensions, check to exit earlier
$mimes = array( ‘image/jpeg’, ‘image/png’, ‘image/gif’ );if( !in_array( $file[‘type’], $mimes ) )
return $file;$img = getimagesize( $file[‘tmp_name’] );
$minimum = array( ‘width’ => 1000, ‘height’ => 1000 );if ( $img[0] < $minimum[‘width’] )
$file[‘error’] =
‘Image too small. Minimum width is ‘
. $minimum[‘width’]
. ‘px. Uploaded image width is ‘
. $img[0] . ‘px’;elseif ( $img[1] < $minimum[‘height’] )
$file[‘error’] =
‘Image too small. Minimum height is ‘
. $minimum[‘height’]
. ‘px. Uploaded image height is ‘
. $img[1] . ‘px’;return $file;
}Thank you in advance.
- The topic ‘Minimum Image Width and Height’ is closed to new replies.