PHPackages                             yaravel/imagevalidator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. yaravel/imagevalidator

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

yaravel/imagevalidator
======================

Custom Laravel Validator for image dimensions

364PHP

Since Jul 27Pushed 10y ago3 watchersCompare

[ Source](https://github.com/yaravel/imagevalidator)[ Packagist](https://packagist.org/packages/yaravel/imagevalidator)[ RSS](/packages/yaravel-imagevalidator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Image Validator Rules For Laravel 5
===================================

[](#image-validator-rules-for-laravel-5)

Extra Laravel validation rules for dealing with images.

[![Latest Stable Version](https://camo.githubusercontent.com/f7b8672d412ae9fd2426100e074011482a96b1c04434fec7eac4950a689a8fdc/68747470733a2f2f706f7365722e707567782e6f72672f6376696562726f636b2f696d6167652d76616c696461746f722f762f737461626c652e706e67)](https://packagist.org/packages/cviebrock/image-validator)[![Total Downloads](https://camo.githubusercontent.com/fbdd6834ea733bdbda8e79ba70005841227dcebbe05b37409206cbea2b7dd9d5/68747470733a2f2f706f7365722e707567782e6f72672f6376696562726f636b2f696d6167652d76616c696461746f722f646f776e6c6f6164732e706e67)](https://packagist.org/packages/cviebrock/image-validator)

- [Installation](#installation)
- [Usage](#usage)
- [Examples](#examples)
- [Bugs, Suggestions and Contributions](#bugs)
- [Copyright and License](#copyright)

Installation
------------

[](#installation)

Install the package through [Composer](http://getcomposer.org).

```
composer require "cviebrock/image-validator:2.0.*@beta"

```

**Note:** Version 2.0 of this package is designed to work with Laravel 5. If you are using Laravel 4, then checkout the `1.x` branch and use the latest version there.

Add the following to your `providers` array in `app/config/app.php`:

```
'providers' => array(
	'Cviebrock\ImageValidator\ImageValidatorServiceProvider',
),
```

Usage
-----

[](#usage)

### image\_size

[](#image_size)

Use it like any `Validator` rule:

```
$rules = array(
	'my_image_field' => 'image_size:[,]',
);
```

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

- `300` or `=300` means the dimension must be exactly 300 pixels.
- `=300` means the dimension must be greater than or equal to 300 pixels
- `200-300` means the dimension must be betweem 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).

### image\_aspect

[](#image_aspect)

```
$rules = array(
	'my_image_field' => 'image_aspect:',
);
```

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

- `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 doesn't matter:

- `~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.

Examples
--------

[](#examples)

```
	// logo must be 300px wide by 400px tall

	$rules = array(
		'logo' => 'required|image|image_size:300,400',
	);

	// logo must be less than or equal to 300x300px.

	$rules = array(
		'logo' => 'required|image|image_size:=100,200-300',
	);

	// logo must be square

	$rules = array(
		'logo' => 'required|image|image_aspect:1',
	);

	// logo must be ready for the big screen TV :)

	$rules = array(
		'logo' => 'required|image|image_aspect:16:9',
	);
```

Bugs, Suggestions and Contributions
-----------------------------------

[](#bugs-suggestions-and-contributions)

Please use [Github](https://github.com/cviebrock/image-validator/issues) for bugs, comments, suggestions.

1. Fork the project.
2. Create your bugfix/feature branch and write your code.
3. Create unit tests for your code:
    - Run `composer install --dev` in the root directory to install required testing packages.
    - Add your test methods to `tests/` (either adding to an existing test file, or creating a new one).
    - Run `vendor/bin/phpunit` to confirm the new (and all previous) tests pass.
4. Commit your changes (and your tests) and push to your branch.
5. Create a new pull request against the imagesize-validator `master` branch.

**Please note that you must create your pull request against the `master` branch. If you have a fix for the Laravel 4 version of the package, make your pull request against the `1.x` branch.**

Copyright and License
---------------------

[](#copyright-and-license)

Eloquent-Sluggable was written by Colin Viebrock and released under the MIT License. See the LICENSE file for details.

Copyright 2013 Colin Viebrock

Thanks
------

[](#thanks)

Lots of thanks to  for the structure of creating a package to add validator rules to Laravel, and setting up useful unit tests.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/49d9c9840441519a6efea94db8ef23f10dadcd38d81f920408789114829554d9?d=identicon)[yaravel](/maintainers/yaravel)

---

Top Contributors

[![darkzdiez](https://avatars.githubusercontent.com/u/5200859?v=4)](https://github.com/darkzdiez "darkzdiez (2 commits)")

### Embed Badge

![Health badge](/badges/yaravel-imagevalidator/health.svg)

```
[![Health](https://phpackages.com/badges/yaravel-imagevalidator/health.svg)](https://phpackages.com/packages/yaravel-imagevalidator)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
