Here we will discuss laravel image fix height and width validation. validate laravel image height width ratio. How validate image min max height and width.
Laravel validate image fix height and width
Laravel use dimensions validation for check image height width. when you want to validate a fix height-width image then use height and width with value in dimensions validation
App/Http/Controllers/ImageController.php<?php namespace App\Http\Controllers; use Illuminate\Http\Request; class ImageController extends Model { public function store(Request $request) { $validation = Validator::make($request->all(), [ 'image' => 'dimensions:width=100,height=200' ]); } }
Laravel validate image width-height ratio
You can also validate image height-width ratio for example only upload a image which width and height ratio is 2:1 its mean width always double of height.
App/Http/Controllers/ImageController.php<?php namespace App\Http\Controllers; use Illuminate\Http\Request; class ImageController extends Model { public function store(Request $request) { $validation = Validator::make($request->all(), [ 'image' => 'dimensions:ratio=2/1' ]); } }
Laravel image min-max height and width validation
Laravel also provide to image min-max height-width validation by help of these constraints min_width, max_width, min_height, max_height.
App/Http/Controllers/ImageController.php<?php namespace App\Http\Controllers; use Illuminate\Http\Request; class ImageController extends Model { public function store(Request $request) { $validation = Validator::make($request->all(), [ 'image' => 'dimensions:min_width=200,min_height=300' ]); } }