PHP code example of crop / yii2-cropimage

1. Go to this page and download the library: Download crop/yii2-cropimage library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

crop / yii2-cropimage example snippets


 
// 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'])
]);

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

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

$ php composer.phar