Image Ratio Validator
allows you to add image validation by its aspect ratio.
The preferred way to install this extension is through composer.
Either run
$ php composer.phar require --prefer-dist zakurdaev/yii2-image-ratio-validator "*"
or add
"zakurdaev/yii2-image-ratio-validator": "*"
to the require
section of your composer.json
file.
Once the extension is installed, simply use it in your code:
public function rules()
{
return [
[['image'], zakurdaev\imageratio\ImageRatioValidator::class, 'ratios' => 1600/1200],
];
}
public function rules()
{
return [
[['image'], zakurdaev\imageratio\ImageRatioValidator::class, 'ratios' => ['from' => 1400/1200, 'to' => 1600/1200]],
];
}
public function rules()
{
return [
[['image'], zakurdaev\imageratio\ImageRatioValidator::class, 'ratios' => [
16/9,
['from' => 100/50, 'to' => 150/50]
]],
];
}
The BSD License (BSD). Please see License File for more information.