crop/yii2-cropimage

基于cropper的一款图片裁切组件

Installs: 6

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 0

Open Issues: 0

Language:JavaScript

Type:yii2-extension

v1.0.1 2019-02-15 03:00 UTC

This package is auto-updated.

Last update: 2025-06-15 16:38:13 UTC


README

==========================

此扩展集成cropper图片裁切上传插件,旨在更好的处理 Yii2 framework 图片上传的前端问题,目前仅支持单图上传。

安装

推荐使用composer进行安装

$ php composer.phar require  crop/yii2-cropimage

使用

视图文件

单图

<?php 
// ActiveForm
echo $form->field($model, 'username')->widget(\yii2\cropimage\CropImagesWidget::className(),['upload_url' => \yii\helpers\Url::toRoute(['site/upload']),'width' => 305,'height' => 230]); 

// 非 ActiveForm
echo '<label class="control-label">图片</label>';
echo \yii2\cropimage\CropImagesWidget::widget([
    'model' => $model,
    'attribute' => 'file',
    'upload_url' => \yii\helpers\Url::toRoute(['site/upload'])
]);
?>

控制器 upload_url上传控制器,控制器需要返回的数据格式如下

// 错误时
{"code": 1, "msg": "error"}

// 正确时, 其中 attachment 指的是保存在数据库中的路径,url 是该图片在web可访问的地址
{"code": 0, "url": "http://domain/图片地址", "attachment": "图片地址"}

许可

yii2-webuploader is released under the MIT License. See the bundled LICENSE.md for details.