## 1. 后台图片管理组件
* https://github.com/noam148/yii2-image-manager
* 配置文件中设置好, 注意对应的目录要设成可写
~~~
'components' => [
'imagemanager' => [
'class' => 'noam148\imagemanager\components\ImageManagerGetPath',
//set media path (outside the web folder is possible)
//原始文件存放路径
// 'mediaPath' => '/path/where/to/store/images/media/imagemanager'
'mediaPath' => Yii::getAlias('@storage/web/img'),
// path relative web folder to store the cache images
// 使用时从cache目录读,如果cache目录内没有,就从原始文件生成。
//cache目录应当是web可访问的目录
//如当backend用时就是cache目录就相对于backend/web下
//当frontend用时, cache目录就相对于frontend/web目录下
//'cachePath' => 'assets/images',
'cachePath' => 'image-cache',
//use filename (seo friendly) for resized images else use a hash
'useFilename' => true,
//show full url (for example in case of a API)
'absoluteUrl' => true,
],
...
],
~~~
~~~
'modules' => [
'imagemanager' => [
'class' => 'noam148\imagemanager\Module',
//set accces rules ()
'canUploadImage' => true,
'canRemoveImage' => function(){
return true;
},
// Set if blameable behavior is used, if it is, callable function can also be used
'setBlameableBehavior' => true,
//add css files (to use in media manage selector iframe)
'cssFiles' => [
'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css',
],
],
...
],
~~~
* 在视图文件中, 使用如下
~~~
<?php echo $form->field($model, 'qr_image_id')
->widget(\noam148\imagemanager\components\ImageManagerInputWidget::className(),
[
'aspectRatio' => 1, // (16/9), (4/3)
'showPreview' => true,
//on true show warning before detach image
'showDeletePickedImageConfirm' => false,
]);
?>
~~~
~~~
$imgUrl = \Yii::$app->imagemanager->getImagePath($this->qr_image_id, 9999, 9999);
~~~
* 初次安装时执行
~~~
php yii migrate --migrationPath=@noam148/imagemanager/migrations
~~~