2017 © Pedro PelĂĄez
 

library image-validator

Custom Laravel Validator for image dimensions - abandoned since these are now built in to Laravel 5.2 and later

image

cviebrock/image-validator

Custom Laravel Validator for image dimensions - abandoned since these are now built in to Laravel 5.2 and later

  • Tuesday, September 5, 2017
  • by cviebrock
  • Repository
  • 9 Watchers
  • 223 Stars
  • 267,764 Installations
  • PHP
  • 10 Dependents
  • 3 Suggesters
  • 56 Forks
  • 1 Open issues
  • 23 Versions
  • 6 % Grown

The README.md

Image-Validator

Extra validation rules for dealing with images in Laravel 5., (*1)

NOTE: As of Laravel version 5.2, there are now built-in validation rules for image dimensions and aspect ratios. This package is not required and will no longer be maintained., (*2)

Build Status Total Downloads Latest Stable Version Latest Unstable Version Scrutinizer Code Quality SensioLabsInsight License: MIT, (*3)


Installation

NOTE: Depending on your version of Laravel, you should install a different version of the package:, (*4)

Laravel Version Package Version
4.* 1.x
5.0–5.3 2.1†
5.4 2.2†
5.5 not supported†

† Laravel 5.2 and later have built-in validation rules for image dimensions., (*5)

Install the package through Composer., (*6)

composer require "cviebrock/image-validator"

Add the following to your providers array in app/config/app.php:, (*7)

'providers' => [
    ...
    \Cviebrock\ImageValidator\ImageValidatorServiceProvider::class,
],

Usage

Use it like any Validator rule. The package offers two rules for image validation:, (*8)

image_size

$rules = [
    'my_image_field' => 'image_size:<width>[,<height>]',
];

The values for width and _height can be integers, or integers with a modifier prefix:, (*9)

  • 300 or =300 means the dimension must be exactly 300 pixels.
  • <300 means the dimension must be less than 300 pixels
  • <=300 means the dimension must be less than or equal to 300 pixels
  • >300 means the dimension must be greater than 300 pixels
  • >=300 means the dimension must be greater than or equal to 300 pixels
  • 200-300 means the dimension must be between 200 and 300 pixels (inclusive)
  • * means the dimension can be any value

If you only pass one value, it's assumed to apply to both dimensions (i.e. a square image with the given dimensions)., (*10)

image_aspect

$rules = [
    'my_image_field' => 'image_aspect:<ratio>',
];

The value for ratio represents width Ă· height and be either a decimal or two values (width, height; both integers):, (*11)

  • 0.75
  • 3,4

The value (or first value, if providing height and width) can also be prefixed with a tilde ~ character, in which case the orientation does not matter:, (*12)

  • ~3,4 means the image can have an aspect ratio of either 3:4 or 4:3.

Note that you may run into issues with floating point rounding., (*13)

Examples

// logo must be 300px wide by 400px tall
$rules = [
    'logo' => 'required|image|image_size:300,400',
];

// logo must be less than or equal to 300x300px.
$rules = [
    'logo' => 'required|image|image_size:<=300',
];

// logo must be 300px wide but can be any height
$rules = [
    'logo' => 'required|image|image_size:300,*',
];

// logo must be at least 100px tall and 200-300 pixels wide (inclusive)
$rules = [
    'logo' => 'required|image|image_size:>=100,200-300',
];

// logo must be square
$rules = [
    'logo' => 'required|image|image_aspect:1',
];

// logo must be ready for the big screen TV :)
$rules = [
    'logo' => 'required|image|image_aspect:16,9',
];

Bugs, Suggestions and Contributions

Thanks to everyone who has contributed to this project!, (*14)

Please use Github for reporting bugs, and making comments or suggestions., (*15)

See CONTRIBUTING.md for how to contribute changes., (*16)

image-validator was written by Colin Viebrock and is released under the MIT License., (*17)

Copyright 2013 Colin Viebrock, (*18)

Thanks

Lots of thanks to https://bitbucket.org/hampel/validate-laravel for the structure of creating a package to add validator rules to Laravel, and setting up useful unit tests., (*19)

The Versions

05/09 2017

dev-master

9999999-dev https://github.com/cviebrock/image-validator

Custom Laravel Validator for image dimensions - abandoned since these are now built in to Laravel 5.2 and later

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator image deprecated

05/09 2017

2.2.3

2.2.3.0 https://github.com/cviebrock/image-validator

Custom Laravel Validator for image dimensions - abandoned since these are now built in to Laravel 5.2 and later

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator image deprecated

04/04 2017

1.x-dev

1.9999999.9999999.9999999-dev https://github.com/cviebrock/image-validator

Custom Laravel 4 Validator for image dimensions

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator image

04/04 2017

1.0.5

1.0.5.0 https://github.com/cviebrock/image-validator

Custom Laravel 4 Validator for image dimensions

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator image

13/12 2016
20/07 2016
19/07 2016
27/05 2016
11/04 2016

2.0.1

2.0.1.0 https://github.com/cviebrock/image-validator

Custom Laravel Validator for image dimensions

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator image

07/10 2015

2.0.0

2.0.0.0 https://github.com/cviebrock/image-validator

Custom Laravel Validator for image dimensions

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator image

04/05 2015

2.0.0-beta

2.0.0.0-beta https://github.com/cviebrock/image-validator

Custom Laravel Validator for image dimensions

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator image

17/02 2015

2.0.0-alpha

2.0.0.0-alpha https://github.com/cviebrock/image-validator

Custom Laravel Validator for image dimensions

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator image

18/06 2014

1.0.4

1.0.4.0 https://github.com/cviebrock/image-validator

Custom Laravel 4 Validator for image dimensions

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator image

04/06 2014

1.0.3

1.0.3.0 https://github.com/cviebrock/image-validator

Custom Laravel 4 Validator for image dimensions

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator image

05/02 2014

1.0.2

1.0.2.0 https://github.com/cviebrock/image-validator

Custom Laravel 4 Validator for image dimensions

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator image

04/02 2014

1.0.1

1.0.1.0 https://github.com/cviebrock/image-validator

Custom Laravel 4 Validator for image dimensions

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator image

04/02 2014

1.0.0

1.0.0.0 https://github.com/cviebrock/image-validator

Custom Laravel 4 Validator for image dimensions

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator image

16/12 2013

0.1.1

0.1.1.0 https://github.com/cviebrock/imagesize-validator

Custom Laravel 4 Validator for image dimensions

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator image

16/12 2013

0.2.0

0.2.0.0 https://github.com/cviebrock/imagesize-validator

Custom Laravel 4 Validator for image dimensions

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator image

16/12 2013

0.1.0

0.1.0.0 https://github.com/cviebrock/imagesize-validator

Custom Laravel 4 Validator for image dimensions

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator image