smister 2015-04-24 15:05:25 24663次浏览 8条评论 19 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

觉得很赞
  • 评论于 2015-04-24 23:34 举报

    这个东东是干嘛的!?

    3 条回复
    评论于 2015-04-26 21:09 回复

    Yii2图片处理插件
    支持驱动:Imagick、Gmagick、Gd
    功能:修剪、缩略、图片水印、文字水印、相框

    评论于 2016-01-06 11:21 回复

    你知道怎么生成缩略图吗??我的直接给裁剪了

    评论于 2019-07-08 15:53 回复

    默认使用的什么驱动?怎么更改使用的驱动啊?

  • 评论于 2015-04-27 19:39 举报

    费这事干嘛?
    用composer多好吖

    2 条回复
    评论于 2015-07-29 11:53 回复

    要是会用composer安装就不用这么折腾啦,大哥你能讲下用它怎么安装吗

    评论于 2017-08-25 12:50 回复


    到vendor外层目录执行如下代码,composer命令,例如
    /home/pubsrv/php-5.5.18/bin/php /home/composer.phar require --prefer-dist yiisoft/yii2-imagine
    执行1-2分钟就好了

    觉得很赞
  • 评论于 2015-07-22 23:24 举报

    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/

    不知道我哪里引用的不对?

    1 条回复
    评论于 2016-03-24 11:09 回复

    扩展再加一下
    'yiisoft/Imagine' =>
    array (

    'name' => 'yiisoft/Imagine',
    'version' => '5.0.0.0',
    'alias' => 
    array (
      '@Imagine' => $vendorDir . '/imagine',
    ),
    

    ),

  • 评论于 2016-01-06 11:21 举报

    我的直接给剪切了 我想等比例缩放一下 有大神知道吗 求指点啊
    Image::thumbnail($savepath, 380, 250)->save(Yii::getAlias($savepath));

  • 评论于 2016-03-24 11:08 举报

    不用改多少代码;把上述文件复制到对应的目录;只需要在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',
        ),
      ),
    
    3 条回复
    评论于 2017-01-25 22:23 回复

    还是composer方便,这些都自动生成了 O(∩_∩)O

    评论于 2017-04-20 16:48 回复

    为什么按照你说的改了后,还是Class 'Imagine\Image\ManipulatorInterface' not found这个错误呢?

    评论于 2017-08-14 16:32 回复

    composer下载之后还需要妹纸吗

  • 评论于 2016-08-22 17:26 举报

    如何在 yii2 使用Imagick ,我已安装好, 使用Imagick时, Imagick的函数都不能用了,还是我引入的错误了
    如:$animation = new \Imagine\Imagick\Imagine();

        //设置生成的格式
        $animation->setFormat('gif');
    

    提示没有setFormat方法

  • 评论于 2017-10-20 11:38 举报

    如和设置透明

    觉得很赞
  • 评论于 2019-01-10 17:52 举报

    这个可以设置透明度吗

您需要登录后才可以评论。登录 | 立即注册