cliff363825 / yii2-image
Yii2 图像组件
dev-master
2017-09-09 11:23 UTC
Requires
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2024-08-29 03:56:12 UTC
README
Yii2 图像组件
此扩展基于 yii-easyImage,用于 Yii2。
安装
安装此扩展的最佳方式是通过 composer。
运行以下命令
php composer.phar require --prefer-dist cliff363825/yii2-image "*"
或者在您的 composer.json
文件的 require 部分添加
"cliff363825/yii2-image": "*"
用法
扩展安装后,只需按照以下方式修改您的应用程序配置
return [ ... 'components' => [ .... 'easyImage' => [ 'class' => 'cliff363825\image\EasyImage', 'driver' => 'GD', 'quality' => 100, 'cachePath' => '/easyimage/', 'cacheTime' => 2592000, 'retinaSupport' => false, 'basePath' => '@webroot', 'baseUrl' => '@web', ] ], ];
####参数
- string
$file
required - 图片文件路径 - string
$driver
- 驱动程序:GD
,Imagick
ThumbOf
您可以直接在 View
中创建缩略图
// 创建并自动缓存
Yii::$app->easyImage->thumbOf('/path/to/image.jpg', ['rotate' => 90]);
// 或者
Yii::$app->easyImage->thumbOf('image.jpg', ['rotate' => 90], ['class' => 'image']);
// 或者
Yii::$app->easyImage->thumbOf('image.png', [ 'resize' => ['width' => 100, 'height' => 100], 'rotate' => ['degrees' => 90], 'sharpen' => 50, 'background' => '#ffffff', 'type' => 'jpg', 'quality' => 60, ]);
注意。 此方法返回 Html::img()
####参数
- string
$file
required - 图片文件路径 - array
$params
- 图片操作方法。请参阅 方法 - array
$htmlOptions
- Html::img() 的选项
有关使用详情,请参阅 文档。