crazysnowflake/yii2-image-cropper 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

crazysnowflake/yii2-image-cropper

Composer 安装命令:

composer require crazysnowflake/yii2-image-cropper

包简介

A Javascript Image Cropper

README 文档

README

Installation

The preferred way to install this extension is through composer. Check the composer.json for this extension's requirements and dependencies. Read this web tip /wiki on setting the minimum-stability settings for your application's composer.json.

To install, either run

$ php composer.phar require crazysnowflake/yii2-image-cropper "^1.0@dev"

or add

"crazysnowflake/yii2-image-cropper": "^1.0@dev"

to the require section of your composer.json file.

Release Changes

NOTE: Refer the CHANGE LOG for details on changes to various releases.

Usage

use crazysnowflake\imagecropper\ImageCropperWidget;

$form = ActiveForm::begin( [
        'id'                   => 'edit-profile',
        'options'              => [ 'enctype' => 'multipart/form-data' ],
        'fieldConfig'          => [
            'inputOptions' => [ 'class' => 'form-control form-control-lg' ]
        ],
    ] );
    
echo $form->field( $model, 'virtualImage' )
          ->widget( ImageCropperWidget::classname(), [
                'options'       => [
                    'id'       => 'user-avatar',
                    'accept'   => 'image/*',
                    'multiple' => false,
                ],
                'templateImage' => $model->avatar ? \yii\helpers\Html::img( $model->avatar ) : null,
            ] )->label( 'Profile Image' )->hint( 'We recommend a square image for best results. The ideal size would be 200px wide by 200px high.', [ 'class' => 'hint-block text-muted' ] ); ?>

ActiveForm::end();

#####Your controller function:

use crazysnowflake\imagecropper\ImageCropper;

 
protected function saveImageProfile() {
    $this->virtualImageProfile = UploadedFile::getInstance($this, 'virtualImageProfile');
    
    if ($this->virtualImageProfile && $this->virtualImageProfile->type === 'image/jpeg') {    
        $data = Yii::$app->request->post( 'cropdata' );
        if( $data && isset($data['virtualImageProfile']) && $data['virtualImageProfile'] ){
            ImageCropper::cropImageSection($this->virtualImageProfile->tempName, $this->virtualImageProfile->tempName, $data['virtualImageProfile']);
        }
        $filename = uniqid() . '.' . $this->virtualImageProfile->extension;
        $this->virtualImageProfile->saveAs(Yii::getAlias('@app') . "/web/uploads/users/" . $filename);
    
    }
}

License

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-05-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固