alvinojutsu/yii2-image-cropper

yii2 图像裁剪器

安装数: 4,283

依赖项: 0

建议者: 0

安全: 0

星标: 1

关注者: 3

分支: 0

开放问题: 1

类型:yii2-extension

dev-master 2017-05-11 13:58 UTC

This package is not auto-updated.

Last update: 2024-09-29 03:04:43 UTC


README

yii2 图像裁剪器

此仓库是基于https://github.com/navatech/yii2-cropper修改的

感谢@lephuong

增强

  • 裁剪一个图像到多个尺寸
  • 缩略图默认尺寸

安装

安装此扩展的首选方式是通过 Composer

运行

php composer.phar require --prefer-dist alvinojutsu/yii2-image-cropper "*"

或添加

"alvinojutsu/yii2-image-cropper": "*"

到您的composer.json文件的require部分。

使用方法

扩展安装后,只需在您的代码中使用它即可

无 $model

<?= \alvinux\imagecropper\Cropper::widget([
    'name' => 'Post[picture]',
    // 'value' => 'https://fengyuanchen.github.io/cropper/images/picture.jpg', // Default blank image if not sett
    'options' => [
        ['width' => 200,'height' => 200],
        ['width' => 500,'height' => 200],
        ['width' => 500,'height' => 100],
    ],
    'showThumbnailCropper' => true, // optional, if ( showThumbnailCropper == false && autoCrop == true ) then 'hidden' else 'show',
    'autoCrop' => true, // optional, default (true), if autoCrop = 'true' there is no "Crop Image" button, if set false then you have to click 'Crop Image' button to get value
    'thumbnail' => ['width' => 250, 'height' => 250], // optional, default 150 x 150
    'pluginOptions' => [
        // https://github.com/fengyuanchen/cropper
        // Options default
        // 'autoCropArea'   => true,
        // 'strict'   => false,
        // 'guides'   => true,
        // 'highlight'   => true,
    ]
]); ?>

有 $model

<?= \alvinux\imagecropper\Cropper::widget([
    'model' => $model,
    'attribute' => 'picture',
    'options' => [
        ['width' => 200,'height' => 200],
        ['width' => 500,'height' => 200],
        ['width' => 500,'height' => 100],
    ],
    'showThumbnailCropper' => true, // optional, if ( showThumbnailCropper == false && autoCrop == true ) then 'hidden' else 'show',
    'autoCrop' => true, // optional, default (true), if autoCrop = 'true' there is no "Crop Image" button, if set false then you have to click 'Crop Image' button to get value
    'thumbnail' => ['width' => 250, 'height' => 250], // optional, default 150 x 150
    'pluginOptions' => [
        //https://github.com/fengyuanchen/cropper
    ]
]); ?>

屏幕截图

  • 无图片默认
    without image
  • 有图片
    with image