开发者

How do I create an image filter in Symfony2 AvalancheImagineBundle?

开发者 https://www.devze.com 2023-04-10 05:27 出处:网络
I\'m using Symfony 2 and I just installed the AvalancheImagineBundle successfully. I created my own thumbnail filter as described in the README, and I created a 2nd filter called \"profile\" which (fo

I'm using Symfony 2 and I just installed the AvalancheImagineBundle successfully. I created my own thumbnail filter as described in the README, and I created a 2nd filter called "profile" which (for the moment just to make sure it works) does the same thing as the thumbnail.

// 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 }

However, I don't want profile to be a thumbnail. My Question: How do I define new "types" of filters?

Edit: I开发者_Go百科've seen the example that the README gives, but I can't understand how to write my own filter. I want to write a simple filter that takes a "width" parameter and scales the image down to have that width.

Update: I've been fiddling with these image filters for a while now, and I am still just as lost as before.... Could someone provide me with a hint in the right direction? I'm working on an open source project if it encourages anyone :)


It's funny to reply to your question here as I'm the creator and maintainer of Imagine :)

Basically, to add a filter to a bundle is a several step process

  • Create filter loader - a class that implements Avalanche\Bundle\ImagineBundle\Imagine\Filter\Loader\LoaderInterface

  • Register it in the Symfony DIC as a service and properly tag it Here is how the default thumbnail filter loader is tagged You can find it in the source of the bundle here - https://github.com/avalanche123/AvalancheImagineBundle/blob/master/Resources/config/imagine.xml#L100

  • Finally, specify your filter in the yaml, use whatever value you specified in the "filter" attribute of your loader tag:

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

Let me know if you run into any issues, additionally, feel free to create issues in the github repository of the bundle.

Cheers!


Did you read the "Load your Custom Filters" chapter in the README? It tells you how to configure your filter.

For an example implementation look at the ThumbnailFilterLoader class.

0

精彩评论

暂无评论...
验证码 换一张
取 消