Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zakurdaev/yii2-image-ratio-validator
ImageRatioValidator for Yii 2
https://github.com/zakurdaev/yii2-image-ratio-validator
yii yii2 yii2-extension
Last synced: 20 days ago
JSON representation
ImageRatioValidator for Yii 2
- Host: GitHub
- URL: https://github.com/zakurdaev/yii2-image-ratio-validator
- Owner: zakurdaev
- License: bsd-3-clause
- Created: 2020-06-29T07:09:08.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-07-08T11:41:58.000Z (over 4 years ago)
- Last Synced: 2024-04-23T04:17:12.998Z (9 months ago)
- Topics: yii, yii2, yii2-extension
- Language: PHP
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# ImageRatioValidator for Yii 2
`Image Ratio Validator` allows you to add image validation by its aspect ratio.
## InstallThe preferred way to install this extension is through [composer](http://getcomposer.org/download/).
Either run
```bash
$ php composer.phar require --prefer-dist zakurdaev/yii2-image-ratio-validator "*"
```or add
```json
"zakurdaev/yii2-image-ratio-validator": "*"
```to the `require` section of your `composer.json` file.
## Usage
Once the extension is installed, simply use it in your code:
### Strict validate
```php
public function rules()
{
return [
[['image'], zakurdaev\imageratio\ImageRatioValidator::class, 'ratios' => 1600/1200],
];
}
```### Range validate
```php
public function rules()
{
return [
[['image'], zakurdaev\imageratio\ImageRatioValidator::class, 'ratios' => ['from' => 1400/1200, 'to' => 1600/1200]],
];
}
```### Multiple validate
```php
public function rules()
{
return [
[['image'], zakurdaev\imageratio\ImageRatioValidator::class, 'ratios' => [
16/9,
['from' => 100/50, 'to' => 150/50]
]],
];
}
```## License
The BSD License (BSD). Please see [License File](LICENSE.md) for more information.