我如何创建一个图像过滤器在Symfony2 AvalancheImagineBundle


How do I create an image filter in Symfony2 AvalancheImagineBundle?

我正在使用Symfony 2,我刚刚成功安装了AvalancheImagineBundle。我像README中描述的那样创建了我自己的缩略图过滤器,并且我创建了第二个名为"profile"的过滤器(目前只是为了确保它能工作),它与缩略图做同样的事情。

// app/config/config.yml
# Avalanche Imagine Configuration
avalanche_imagine:
    web_root:     %kernel.root_dir%/../web
    cache_prefix: images/cache
    driver:       gd
    filters:
        my_thumb:
            type:    thumbnail
            options: { size: [100, 100], mode: outbound }
        profile:
            type:    thumbnail         <-- HOW DO I DEFINE OTHER TYPES?
            options: { size: [200, 200], mode: outbound }

然而,我不希望配置文件是缩略图。我的问题:我如何定义过滤器的新"类型"?

编辑:我已经看到了README给出的例子,但我不明白如何编写我自己的过滤器。我想写一个简单的过滤器,它接受一个"宽度"参数,并将图像缩小到具有该宽度。

更新:我已经摆弄这些图像过滤器一段时间了,我仍然像以前一样迷路....有人能给我指点一下正确的方向吗?我正在做一个开源项目,如果它鼓励任何人的话:)

在这里回答你的问题很有趣,因为我是Imagine的创建者和维护者:)

基本上,向包中添加过滤器是一个有几个步骤的过程

  • 创建过滤器加载器-实现Avalanche'Bundle'ImagineBundle'Imagine' filter ' loader 'LoaderInterface

  • 在Symfony DIC中将其注册为服务并正确标记它下面是默认缩略图过滤器加载器的标记方式你可以在这个包的源代码中找到它- https://github.com/avalanche123/AvalancheImagineBundle/blob/master/Resources/config/imagine.xml#L100

  • 最后,在yaml中指定你的过滤器,使用你在loader标签的"filter"属性中指定的任何值:

    avalanche_imagine:
        filters:
            my_thumb:
                type:    <your filter name>
                options: { #your options# }
    

如果你遇到任何问题,请告诉我,另外,请随意在bundle的github存储库中创建问题。

干杯!

你读了README中的"Load your Custom Filters"一章了吗?它告诉您如何配置过滤器。

查看ThumbnailFilterLoader类的实现示例。

相关文章:
  • 没有找到相关文章