mindkomm / timmy

Advanced image handling for Timber.
MIT License
171 stars 13 forks source link

Running filters during upload #31

Closed parkerwebteam closed 1 year ago

parkerwebteam commented 4 years ago

Hello,

I wonder if it's possible to run a filter and/or custom filter when defining sizes? Apologies if I have missed this in the documentation.

        'image-article_small' => array(
            'show_in_ui' => false,
            'resize' => array(640, 350, 'center'),
            'name' => 'Image article small',
        ),

Something like

        'image-article_small' => array(
            'show_in_ui' => false,
            'resize' => array(640, 350, 'center'),
            'webp' => true, // Uses the same towebp filter that comes with timber
            'filters' => array('my_custom_filter '), // Uses a custom filter added to twig
            'name' => 'Image article small',
        ),

No worries if this doesn't exist, as towebp does of course crunch the images upload first visit, and so should a custom filter. Just trying to achieve best possible performance.

gchtr commented 4 years ago

Hey @parkerwebteam, sorry I didn’t respond earlier.

What would your my_custom_filter do? Can you make an example? If the idea is to add support for WebP conversion, I should probably add that directly.

We’ll need this in the future anyway, I’ll add it to my todo list.

parkerwebteam commented 4 years ago

Hello @gchtr

WebP generation would be great - in this instance we setup "blur" filter which created a very small image blurred for the Image Blur Up technique, and did TimberImage | resize | blur which resulted in some very heavy load on the server.

With it already being generated on upload this would just be a disk read.

gchtr commented 1 year ago

Check out the latest 1.0.0 release, which comes with WebP support, see:

To add a custom filter, it would probably be best if you extend Timmy’s image class with your own filter functionality and then use the v1 API to call your function.