Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retina support for the TimberImageHelper class #371

Closed
aristath opened this issue Oct 22, 2014 · 9 comments
Closed

retina support for the TimberImageHelper class #371

aristath opened this issue Oct 22, 2014 · 9 comments

Comments

@aristath
Copy link
Contributor

This is a suggestion:

Adding retina support to the TimberImageHelper class would be relatively easy...
We'd have to basically create 2 files when we resize an image with width=W and Height=H:

  1. file-nameWxH.png (already handled)
  2. file-nameWxH@2x.png

The 2nd file would then have a resolution of 2Wx2H instead of WxH.

opinions?

@jarednova
Copy link
Member

I agree this is a path to go. is the @2x naming convention still the standard?

@aristath
Copy link
Contributor Author

Yes, it is... But we could take this a step further and add 3 options in the global configuration, or using a filter:

  • enable/disable retina (boolean)
  • retina multiplier (int)
  • retina suffix (string)

This way we can be ready for whatever comes our way. Retina in 2 years may be 4x and not 2x, so why limit ourselves! :)

@jarednova
Copy link
Member

Agreed, I don't think 2x is the end-of-the-line on this one. In terms of the interaction, the resize filter already has a bunch of parameters -- rather than append, I'm interested in add a fresh one, for example...

<img src="{{ post.thumbnail.src | resize(600, 400) | retina(2) }}" />

For example, with srcset:

<img src="{{ post.thumbnail.src }}" srcset="{{ post.thumbnail.src | retina(1) }} 1x, 
    {{ post.thumbnail.src | retina(2) }}  2x, 
    {{ post.thumbnail.src | retina(3) }}  3x, 
    {{ post.thumbnail.src | retina(4) }}  4x">

... I'm with you on the global config but torn about the way to do it. Right now things are generally set through Timber::$properties, but I'm interested in a way of making that better before just throwing new properties (or filters) in there.

@aristath
Copy link
Contributor Author

I like it... 👍

@aristath
Copy link
Contributor Author

I was actually able to do that semi-manually... https://github.com/presscodes/maera-bootstrap/blob/896e0a8da26bd8ef9ca394b7faa73ad72ac7d149/views/single-top.twig
I had not thought of using scrset!

Though having this happen behind the scenes in Timber would make it a lot easier 😉

jarednova added a commit that referenced this issue Oct 26, 2014
@jarednova
Copy link
Member

Hey @aristath -- I've got a branch with all the magic built-right-in:

https://github.com/jarednova/timber/tree/371_retina

You can now do...

<img src="{{ post.thumbnail.src | retina }}" />
<img src="{{ post.thumbnail.src | retina(3) }}" />
<img src="{{ post.thumbnail.src | resize(400, 400) | retina }}" />

@aristath
Copy link
Contributor Author

Seems to be working fine!!

@jarednova
Copy link
Member

Awesome! I've thrown a bunch of tests at it and it's working great -- pulling into master....

@jarednova
Copy link
Member

closed by #377

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants