bigdropinc / yii2-image-manager-mongo
用于MongoDB上传、管理和裁剪图像的Yii2模块/小部件
v2.6.3
2018-11-20 12:53 UTC
Requires
- dev-master
- v2.6.3
- v2.6.2
- v2.6.1
- v2.6.0
- v2.5.14
- v2.5.13
- v2.5.12
- v2.5.11
- v2.5.10
- v2.5.9
- v2.5.8
- v2.5.7
- v2.5.6
- v2.5.5
- v2.5.4
- v2.5.3
- v2.5.2
- v2.5.1
- v2.5
- v2.4
- v2.3.2
- v2.3.1
- v2.3
- v2.2
- v2.1.18
- v2.1.17
- v2.1.16
- v2.1.15
- v2.1.14
- v2.1.13
- v2.1.12
- v2.1.11
- v2.1.10
- v2.1.9
- v2.1.8
- v2.1.7
- v2.1.6
- v2.1.5
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1
- v2.0
- 1.2.6
- 1.2.5
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-content_type
- dev-pl_max_file_count
- dev-s3_support
- dev-tags
This package is not auto-updated.
Last update: 2024-09-18 20:14:43 UTC
README
一个用于上传、管理和裁剪图像的Yii2模块/小部件
安装
安装此扩展的首选方式是通过 composer.
- 运行以下命令之一
php composer.phar require "bigdropinc/yii2-image-manager-mongo" "*"
或
"bigdropinc/yii2-image-manager-mongo" : "*"
将以下内容添加到您应用程序的 composer.json
文件的require部分。
- 在您应用程序的配置文件中的
components
部分添加一个新的组件,例如
'components' => [ 'imagemanager' => [ 'class' => 'noam148\imagemanager\components\ImageManagerGetPath', //set media path (outside the web folder is possible) 'mediaPath' => '/path/where/to/store/images/media/imagemanager', //path relative web folder to store the cache images 'cachePath' => ['assets/images'], //use filename (seo friendly) for resized images else use a hash 'useFilename' => true, //show full url (for example in case of a API) 'absoluteUrl' => false, 'databaseComponent' => 'db' // The used database component by the image manager, this defaults to the Yii::$app->db component 'useTinyPng' => true, 'useS3' => true, 's3Configuration' => [ 'key' => 'key', 'secret' => 'key123', 's3Url' => 'https://:9001/', //endpoint set only for local version of services such as minio 'endpoint' => 'https://:9000', 'defaultBucket' => 'default', ] ], ],
并在modules
部分,例如
'modules' => [ 'imagemanager' => [ 'class' => 'noam148\imagemanager\Module', //set accces rules () 'canUploadImage' => true, 'canRemoveImage' => function(){ return true; }, 'deleteOriginalAfterEdit' => false, // false: keep original image after edit. true: delete original image after edit // Set if blameable behavior is used, if it is, callable function can also be used 'setBlameableBehavior' => false, //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', ], ], ],
使用方法
要加载图像选择器,请参阅以下内容(确保您在表中有一个字段,模块可以存储ImageManager表的'id')
echo $form->field($model, 'ImageManager_id_avatar')->widget(\noam148\imagemanager\widgets\ImageManagerInput::className(), [ 'aspectRatio' => (16/9), //set the aspect ratio 'cropViewMode' => 1, //crop mode, option info: https://github.com/fengyuanchen/cropper/#viewmode 'showPreview' => true, //false to hide the preview 'showDeletePickedImageConfirm' => false, //on true show warning before detach image 'multiple' => false, 'models' => $models, //selected models ]);
如果您想使用图像
/* * $ImageManager_id (id that is store in the ImageManager table) * $width/$height width height of the image * $thumbnailMode = "outbound" or "inset" */ \Yii::$app->imagemanager->getImagePath($ImageManager_id, $width, $height,$thumbnailMode)
支持CKEditor & TinyMce
要在CKEditor中使用文件浏览器,请将filebrowserImageBrowseUrl添加到CKEditor小部件的clientOptions中。我只在2amigOS的CKEditor上进行了测试,但它需要适用于其他CKEditor小部件。
use dosamigos\ckeditor\CKEditor; echo $form->field($model, 'text')->widget(CKEditor::className(), [ 'options' => ['rows' => 6], 'preset' => 'basic', 'clientOptions' => [ 'filebrowserImageBrowseUrl' => yii\helpers\Url::to(['imagemanager/manager', 'view-mode'=>'iframe', 'select-type'=>'ckeditor']), ] ]);
要在TinyMce中使用文件浏览器,请将file_browser_callback添加到TinyMce小部件的clientOptions中。我只在2amigOS的TinyMce上进行了测试,但它需要适用于其他TinyMce小部件。(不要忘记将'image'添加到您的'plugins'数组中)
use dosamigos\tinymce\TinyMce; echo $form->field($model, 'text')->widget(TinyMce::className(), [ 'options' => ['rows' => 6], 'language' => 'nl', 'clientOptions' => [ 'file_browser_callback' => new yii\web\JsExpression("function(field_name, url, type, win) { window.open('".yii\helpers\Url::to(['imagemanager/manager', 'view-mode'=>'iframe', 'select-type'=>'tinymce'])."&tag_name='+field_name,'','width=800,height=540 ,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no'); }"), 'plugins' => [ "advlist autolink lists link charmap print preview anchor", "searchreplace visualblocks code fullscreen", "insertdatetime media table contextmenu paste image" ], 'toolbar' => "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image" ] ]);
如果您有任何问题、技巧或反馈,请告诉我!