yii2-imagine配置 [ 2.0 版本 ]
yii2-imagine的拓展和imagine插件是分开的 , yii2只提供了拓展 , 刚好用到yii2 , 搞了一天终于解决了 , 分享一下心得给大家,希望大家少走点弯路。
1、首先从官网下载yii2-imagine的拓展
下载地址:https://github.com/yiisoft/yii2-imagine
下载包名称:yii2-imagine-master
2、然后再下载imagine的插件包
下载地址:https://github.com/avalanche123/Imagine/releases
下载包名称:Imagine-0.5.0.zip
在阅读了yii2-imagine的代码后,我发觉v0.5.0的版本完全兼容。所以大家下载v0.5.0的版本就可以了
3、在项目yii2的vendor\yiisoft\yii2目录下创建一个imagine目录
a) 解压yii2-imagine-master , 将BaseImage.php还有Image.php复制到imagine目录中
b) 解压Imagine-0.5.0.zip ,将Imagine-0.5.0\lib\Imagine目录 , 复制到imagine目录下
c) 将vendor\yiisoft\yii2\imagine下的所有页面,含有
namespace Imagine\
替换成
namespace yii\imagine\Imagine\
含有
use Imagine\
替换成
use yii\imagine\Imagine\
d) 修改vendor\yiisoft\yii2\imagine\BaseImage.php
89行:return new \Imagine\Gmagick\Imagine();
改成 return new Imagine\Gmagick\Imagine();
94行:return new \Imagine\Imagick\Imagine();
改成 return new Imagine\Imagick\Imagine();
99行:return new \Imagine\Gd\Imagine();
改成 return new Imagine\Gd\Imagine();
e) 修改vendor\yiisoft\yii2\imagine\Imagine\Image\Box.php
在头部追加
use yii\imagine\Imagine\Image\BoxInterface;
4、大功告成,测试
<?php
use yii\imagine\Image;
//图片路径请根据自己的项目的位置调整
Image::frame('path/to/image.jpg', 5, '666', 0)
->rotate(-8)
->save('path/to/destination/image.jpg', ['quality' => 50]);
?>
转载至于smister.com
smister
最后登录:2016-07-03
在线时长:12小时24分
- 粉丝30
- 金钱140
- 威望30
- 积分560
共 8 条评论
这个东东是干嘛的!?
Yii2图片处理插件
支持驱动:Imagick、Gmagick、Gd
功能:修剪、缩略、图片水印、文字水印、相框
@柏新星 你知道怎么生成缩略图吗??我的直接给裁剪了
@柏新星 默认使用的什么驱动?怎么更改使用的驱动啊?
费这事干嘛?
用composer多好吖
要是会用composer安装就不用这么折腾啦,大哥你能讲下用它怎么安装吗
@qq260101081
到vendor外层目录执行如下代码,composer命令,例如
/home/pubsrv/php-5.5.18/bin/php /home/composer.phar require --prefer-dist yiisoft/yii2-imagine
执行1-2分钟就好了
hi 你好:
我使用
php composer.phar require --prefer-dist yiisoft/yii2-imagine
安装好了yii2-imagine插件,然后依赖库imagine/imagine也安装了,但是使用的时候还是报
PHP Fatal Error – yii\base\ErrorException Class 'Imagine\Image\ManipulatorInterface' not found
yii2扩展文件中也已经添加
'yiisoft/yii2-imagine' => array ( 'name' => 'yiisoft/yii2-imagine', 'version' => '9999999-dev', 'alias' => array ( '@yii/imagine' => $vendorDir . '/yiisoft/yii2-imagine', ), ),
vender目录结构:
denghp@denghp:~/webroot/yii2-demo$ ll vendor/
total 76
drwxrwxr-x 18 denghp denghp 4096 6月 27 22:50 ./
drwxrwxr-x 13 denghp denghp 4096 7月 22 23:18 ../
-rw-rw-r-- 1 denghp denghp 183 6月 23 22:37 autoload.php
drwxrwxr-x 3 denghp denghp 4096 6月 23 22:37 fzaninotto/
drwxr-xr-x 3 denghp denghp 4096 6月 27 22:49 imagine/
drwxrwxr-x 11 denghp denghp 4096 7月 22 23:22 yiisoft/
denghp@denghp:~/webroot/yii2-demo$ ll vendor/yiisoft/
total 52
drwxrwxr-x 11 denghp denghp 4096 7月 22 23:22 ./
drwxrwxr-x 18 denghp denghp 4096 6月 27 22:50 ../
-rw-rw-r-- 1 denghp denghp 7478 7月 22 22:56 extensions.php
drwxrwxr-x 27 denghp denghp 4096 6月 23 22:37 yii2/
drwxrwxr-x 2 denghp denghp 4096 6月 23 22:37 yii2-bootstrap/
drwxrwxr-x 2 denghp denghp 4096 6月 23 22:37 yii2-codeception/
drwxrwxr-x 2 denghp denghp 4096 6月 23 22:37 yii2-composer/
drwxrwxr-x 9 denghp denghp 4096 6月 23 22:37 yii2-debug/
drwxrwxr-x 2 denghp denghp 4096 6月 23 22:37 yii2-faker/
drwxrwxr-x 8 denghp denghp 4096 6月 23 22:37 yii2-gii/
drwxr-xr-x 2 denghp denghp 4096 6月 27 22:50 yii2-imagine/
drwxrwxr-x 2 denghp denghp 4096 6月 23 22:37 yii2-swiftmailer/
不知道我哪里引用的不对?
扩展再加一下
'yiisoft/Imagine' =>
array (
'name' => 'yiisoft/Imagine', 'version' => '5.0.0.0', 'alias' => array ( '@Imagine' => $vendorDir . '/imagine', ),
),
我的直接给剪切了 我想等比例缩放一下 有大神知道吗 求指点啊
Image::thumbnail($savepath, 380, 250)->save(Yii::getAlias($savepath));
不用改多少代码;把上述文件复制到对应的目录;只需要在vendor/yiisoft/extensions.php增加这2个引入就可以
'yiisoft/yii2-imagine' => array ( 'name' => 'yiisoft/yii2-imagine', 'version' => '2.0.3.0', 'alias' => array ( '@yii/imagine' => $vendorDir . '/yiisoft/yii2-imagine', ), ), 'yiisoft/Imagine' => array ( 'name' => 'yiisoft/Imagine', 'version' => '5.0.0.0', 'alias' => array ( '@Imagine' => $vendorDir . '/imagine', ), ),
还是composer方便,这些都自动生成了 O(∩_∩)O
为什么按照你说的改了后,还是Class 'Imagine\Image\ManipulatorInterface' not found这个错误呢?
@沐风待雨 composer下载之后还需要妹纸吗
如何在 yii2 使用Imagick ,我已安装好, 使用Imagick时, Imagick的函数都不能用了,还是我引入的错误了
如:$animation = new \Imagine\Imagick\Imagine();
//设置生成的格式 $animation->setFormat('gif');
提示没有setFormat方法
如和设置透明
这个可以设置透明度吗