mindkomm / timmy

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

Support for Letterboxing #3

Open lmartins opened 8 years ago

lmartins commented 8 years ago

Any plans to support the letterboxing cropping mode: https://github.com/jarednova/timber/wiki/Image-cookbook#letterboxing-images

gchtr commented 8 years ago

Yeah, sure, that could be implemented.

What do you think, would it make sense to use letterbox like this in the image configuration?

'custom-4-crop' => array(
    // output should be 370, 370
    'resize' => array( 370, 370 ),
    // use letterbox with color #bada55
    'letterbox' => '#bada55',
)

When I’d use a parameter letterbox, it would take the resize parameters to letterbox the image.

In addition to that, I also thought about using the tojpg filter.

'custom-4-crop' => array(
    'resize' => array( 240 ),
    // convert to jpg with background #c0ffee when image is not a jpg
    'tojpg' => '#c0ffee',
)

When I’d use a parameter tojpg, it would convert PNGs to JPGs and use the assigned color to fill transparent space in the image (This is not possible with the normal Timber filter, but it’s possible if we directly go through a TimberImageHelper function).

Of course you could also use both. In that case it would first convert the image to JPG and then letterbox it.

Would it also make sense to use it with a twig filter? Like this:

<img {{post.thumbnail|to_jpg|get_timber_image_responsive('header')}}>

What do you think? I’ve never used any of the two filters before, so your opinion about how you could work with that would be nice ;).

lmartins commented 8 years ago

Sorry for not answering this before. We have a few hours difference. Your suggestions seem spot on I think.

lmartins commented 8 years ago

Since the issue has been closed, is this something planned for a future release?

gchtr commented 8 years ago

Huh? Why did I close that? Of course it’s not supposed to be closed!

Thanks for the feedback. I’ll implement this in the next days.

lmartins commented 8 years ago

@gchtr Thanks Lukas.

gchtr commented 8 years ago

@lmartins Hey Luis.

I added support for letterbox and tojpg filters in 08ac4f3cab9dd47ab9f8046d45cda70cef6f13b2. When you download the latest version, you should be good to go.

lmartins commented 8 years ago

@gchtr Hi Lukas,

I can confirm it is now working. I couldn't get letterbox to work as a filter, as in <img {{ post.thumbnail|letterbox('#fff')|get_timber_image_responsive('product-tile') }} itemprop="image"> but other than that it is working great. Thanks man.

gchtr commented 8 years ago

I didn’t implement the direct use of these filters in Twig yet. I’ll see what I can do.

lmartins commented 8 years ago

Ah ok. It is not essential in my use case, just a nice to have.