定制 calcio/yii2-image-cutter 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

calcio/yii2-image-cutter

Composer 安装命令:

composer require calcio/yii2-image-cutter

包简介

Yii2 crop image widget with Bootstrap 5

README 文档

README

This is a fork mtrim//yii2-image-cutter

Features:

  • Bootstrap5
  • Upload image
  • Crop image
  • Use Imagine

cutter

Composer

The preferred way to install this extension is through Composer.

Either run php composer.phar require --prefer-dist calcio/yii2-image-cutter "dev-master"

or add "calcio/yii2-image-cutter": "dev-master" to the require section of your composer.json

Use

  • Add to the model behavior
    use calcio\cutter\behaviors\CutterBehavior;

    public function behaviors()
    {
        return [
            'image' => [
                'class' => CutterBehavior::className(),
                'attributes' => 'image',
                'baseDir' => '/uploads/crop',
                'basePath' => '@webroot',
            ],
        ]
    }
    
    public function rules()
    {
        return [
            ['image', 'file', 'extensions' => 'jpg, jpeg, png', 'mimeTypes' => 'image/jpeg, image/png'],
        ];
    }

Parameters

  • integer attributes required (string) - Image attributes
  • integer baseDir required - Base directory
  • integer basePath required - Base path
  • integer quality = 92 - Crop result quality
  • Use in view

Without client validation

    <div class="form-group">
        <label class="control-label">Image</label>
        <?= \calcio\cutter\Cutter::widget([
            'model' => $model,
            'attribute' => 'image'
        ]); ?>
    </div>

or

With client validation

    <?= $form->field($model, 'image')->widget(\calcio\cutter\Cutter::className(), [
        //options
    ]); ?>
  • Use in view

Get url to image

    $model->getImg(100);
    $model-> getImgOrigin();

Widget method options

  • model (string) (obligatory)

Defines the model that will be used to make the form input field.

  • attribute (string) (obligatory)

Defines the model attribute that will be used to make de form input field.

  • useWindowHeight (bool) (optional)

Use the height of the current window for the form image cropping

  • imageOptions (array) (optional)

List with options that will be added to the image field that will be used to define the crop data in the modal. The format should be ['option' => 'value'].

  • cropperOptions (array) (optional)

List with options that will be added in javaScript while creating the crop object. For more information about which options can be added you can read this web.

统计信息

  • 总下载量: 161
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 1
  • 开发语言: JavaScript

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2022-02-25