0

我正在尝试对基于 LiipImagineBundle 的图像应用过滤器。

以下是步骤:

  1. 通过添加此行通过 composer 文件进行安装:

    "liip/imagine-bundle": "1.0.*@dev"

  2. 通过添加以下行来配置 config.yml 文件:

    liip_imagine:
        resolvers:
        default:
            web_path:  
                web_root: %kernel.root_dir%/../web
                cache_prefix: media/cache
    
    filter_sets:
        cache: ~
        my_thumb:
            quality: 75
            filters:
              thumbnail: { size: [120, 90], mode: outbound }
    
  3. AppKernel.php 中的 bundle 声明:

    new Liip\ImagineBundle\LiipImagineBundle(),
    
  4. 通过在 twig 文件中添加一行来测试包:

    <img src="{{ asset('img/test.jpg') | imagine_filter('my_thumb') }}" />
    

但是,没有显示图像。生成的 HTML 文件包含:

<img src="http://localhost/tuto/web/app_dev.php/media/cache/my_thumb/img/test.jpg">

在浏览器的 javascript 控制台中,我发现了这个错误:

GET http://localhost/tuto/web/app_dev.php/media/cache/my_thumb/img/test.jpg 500 (Internal Server Error)

当我尝试打开链接时(带有 500 Internal Server Error),symfony 抛出这个错误:

Failed to create /home/amine/NetBeansProjects/tuto/app/../web/media/cache/my_thumb/img 500 Internal Server Error - IOException

我想我没有创建以下文件夹的权限:/home/amine/NetBeansProjects/tuto/app/../web/media/cache/my_thumb/img. 在我看来,自从我在 Ubuntu 上工作以来,这是可以预料的。

web为了避免这个问题,我直接通过更改文件夹的权限,sudo chmod 777 -R web但问题还是一样。

有什么想法吗?

4

2 回答 2

0

我以为它正在工作,但事实并非如此!它正在从旧缓存加载图像。忘记我的最后一个帖子!

我认为捆绑中有一个错误。我解释:

这是我的捆绑包的新配置:

    liip_imagine:
        resolvers:
        default:
            web_path:  
                web_root: %kernel.root_dir%/../web/img
                # %kernel.root_dir%/../web/img is the folder where filtered images will be created!
                cache_prefix: media/cache
                # media/cache the prefix of folder where the cached images will be created

    filter_sets:
        cache: ~
        my_thumb:
            quality: 75
            filters:
              thumbnail: { size: [120, 90], mode: outbound }

这是用于显示图像的树枝部分:

{# This way the filtered image will not be created!#}
<img src="{{ 'img/test.jpg' | imagine_filter('my_thumb') }}" />

{# That way, the filted images will be created. asset() must be used. #}
<img src="{{ asset('img/test.jpg' | imagine_filter('my_thumb')) }}" />

生成的图片链接不正确!其实得到的链接是:

http://localhost/media/cache/my_thumb/img/test.jpg

预期的正确链接是:

http://localhost/**tuto/web/img**/media/cache/my_thumb/img/test.jpg

tuto/web/img中有一个缺失的部分。这是一个错误吗?

为了避免这个问题,我这样做了:

<img src="{{ asset('img/test.jpg' | imagine_filter('my_thumb'))|replace({'media':'tuto/web/img/media'}) }}" />

我猜:玩树枝不是一个好的解决方案。我希望我们能找到解决这个错误的方法!

谢谢!

于 2014-03-22T11:19:42.183 回答
0

问题几乎解决了。我像这样更改了 config.yml:

    liip_imagine:
        resolvers:
        default:
            web_path:  
                web_root: %kernel.root_dir%/../web/imagine
                # imagine is the folder where filtered images will be created!
                cache_prefix: tuto/web/imagine/media/cache
                # where tuto is the folder of my symfony application

    filter_sets:
        cache: ~
        my_thumb:
            quality: 75
            filters:
              thumbnail: { size: [120, 90], mode: outbound }

对于树枝部分,它已更改为:

<img src="{{ 'img/test.jpg' | imagine_filter('my_thumb') }}" />
{# where img is the folder where I put all my images!#}

我的问题是:是否有可能以我用其他东西cache_prefix替换的方式更改参数的配置,以便让配置在任何地方都可以使用?tuto我问这个问题是因为我在托管网站时会避免出现问题!

谢谢...

于 2014-03-22T07:15:32.073 回答