Image Dimensions Validation

Submitted by aglipanci - 4 years ago

Custom image dimensions validator for minimum height and width.

Validator::extend('img_min_size', function($attribute, $value, $parameters)
    	{
		        $file = Request::file($attribute);
		        $image_info = getimagesize($file);
		        $image_width = $image_info[0];
		        $image_height = $image_info[1];
		        if( (isset($parameters[0]) && $parameters[0] != 0) && $image_width < $parameters[0]) return false;
		        if( (isset($parameters[1]) && $parameters[1] != 0) && $image_height < $parameters[1] ) return false;
		        return true;
		});
        
//also add the validator error string in the validator lang file.

//to use it
$rules = array(
            'image1' => 'img_min_size:650,350'
            );
comments powered by Disqus