PHP code example of moxuandi / yii2-umeditor
1. Go to this page and download the library: Download moxuandi/yii2-umeditor 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/ */
moxuandi / yii2-umeditor example snippets
public function actions()
{
return [
'UmeUpload' => [
'class' => 'moxuandi\umeditor\UploaderAction',
// 可选参数, 参考 UploaderAction::$_config
'config' => [
'allowFiles' => ['.png', '.jpg', '.jpeg', '.gif', '.bmp'], // 允许上传的文件类型
'pathFormat' => '/uploads/image/{yyyy}{mm}{dd}/{hh}{ii}{ss}_{rand:6}', // 文件保存路径
// 图片上传根目录, 配合`views`中的`$imagePath`使用
'rootPath' => dirname(Yii::$app->request->scriptFile),
'rootUrl' => Yii::$app->request->hostInfo,
],
],
];
}
1. 简单调用:
$form->field($model, 'content')->widget('moxuandi\umeditor\UMEditor');
2. 带参数调用:
$form->field($model, 'content')->widget('moxuandi\umeditor\UMEditor', [
'editorOptions' => [
// 编辑区域的大小
'initialFrameWidth' => '100%',
'initialFrameHeight' => 400,
// 图片修正地址, 配合`actions`中的`$rootPath`使用
//'imagePath' => 'http://image.yii2advanced.com',
// 定制菜单
'toolbar' => ['undo redo | bold italic underline'],
]
]);
3. 不带 $model 调用:
\moxuandi\umeditor\UMEditor::widget([
'name' => 'content',
'editorOptions' => [
'initialFrameWidth' => '100%',
]
]);
'config' => [
'process' => [
// 缩略图
'thumb' => [
'width' => 300,
'height' => 200,
//'mode' => 'outbound', // 'inset'(补白), 'outbound'(裁剪, 默认值)
],
// 裁剪图像
'crop' => [
'width' => 300,
'height' => 200,
//'top' => 0,
//'left' => 0,
],
// 添加边框
'frame' => [
'margin' => 20,
//'color' => '666',
//'alpha' => 100,
],
// 添加图片水印
'watermark' => [
'watermarkImage' => '@web/uploads/watermark.png',
//'top' => 0,
//'left' => 0,
],
// 添加文字水印
'text' => [
'text' => '水印文字',
'fontFile' => '@web/uploads/simhei.ttf', // 字体文件的位置
/*'fontOptions' => [
'size' => 12,
'color' => 'fff',
'angle' => 0,
],*/
//'top' => 0,
//'left' => 0,
],
// 调整图片大小
'resize' => [
'width' => 300,
'height' => 200,
//'keepAspectRatio' => true, // 是否保持图片纵横比
//'allowUpscaling' => false, // 如果原图很小, 图片是否放大
],
],
],