Laravel - image dimension validation rules example

About Us:

We are from free coder. We are a group of web developers who are passionate about web development. You can learn from us php, laravel, node js, vue js, react js and many other topic on web developement.
we are very happy to help you.
free coder

Today what you are going to learn:

Laravel provide new image dimensions validation option for image upload and you are able to use this dimensions validation in laravel 6, laravel 7 and laravel 8 application. In this validation rules we can set several rules like as listed bellow:

Dimensions Rules:








In this Dimensions option through we can set fix width and height, if invalid width and height of image then it will return error. Same way we can set validation min and max height width on your validation.

Few days ago i posted image upload with validation post in Laravel 5.3, you can see here : Laravel 5.3 Image Upload with Validation lesson.

In this post i used simple validation with mime type and max size like as bellow :

$this->validate($request, [

'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',


You can also replace your validation using Dimensions rules like as bellow:

Lesson 1:

$this->validate($request, [

'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048|dimensions:width=500,height=500',


Lesson 2:

$this->validate($request, [

'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048|dimensions:min_width=350,min_height=600',


Lesson 3:

$this->validate($request, [

'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048|dimensions:max_width=350,max_height=600',


Lesson 4:

$this->validate($request, [

'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048|dimensions:ratio=3/2',


You can check this rules with image uploading post...

Recent Posts

Related Posts