It's possible to not only validate image file types, but also dimensions.
Take the following example of uploading an avatar:
$request->validate([
'avatar' => ['required', 'image', 'dimensions:min_width=100,min_height=200']
]);
That's it. Just tweak min_width
and min_height
. Of course, you also have max_
available:
$request->validate([
'avatar' => ['required', 'image', 'dimensions:min_width=100,min_height=200,max_width=300,max_height=500']
]);
If you prefer class-based rules, this generally makes it easier when validating images:
$request->validate([
'avatar' => [
'required',
File::image()
->min(1024) // file size
->max(12 * 1024) // file size
->dimensions(
Rule::dimensions()->maxWidth(300)->maxHeight(500) //etc
),
],
]);
With the Rule::dimensions()
methods you chain on, they're pretty guessable, but head to the docs for everything available.