zakurdaev/yii2-image-ratio-validator

Use editor.js in form. Module for Yii2

dev-master 2020-07-08 11:41 UTC

This package is auto-updated.

Last update: 2024-05-08 21:06:31 UTC


README

Image Ratio Validator allows you to add image validation by its aspect ratio.

Install

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.

Usage

Once the extension is installed, simply use it in your code:

Strict validate

    public function rules()
    {
        return [
            [['image'], zakurdaev\imageratio\ImageRatioValidator::class, 'ratios' => 1600/1200],
        ];
    }

Range validate

    public function rules()
    {
        return [
            [['image'], zakurdaev\imageratio\ImageRatioValidator::class, 'ratios' => ['from' => 1400/1200, 'to' => 1600/1200]],
        ];
    }

Multiple validate

    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 for more information.