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 images in combination with manual derivatives #1016

Closed
fredrikekelund opened this issue Sep 1, 2016 · 5 comments
Closed

Retina images in combination with manual derivatives #1016

fredrikekelund opened this issue Sep 1, 2016 · 5 comments

Comments

@fredrikekelund
Copy link
Contributor

I want to generate srcset attributes for the images I'm using so that they both scale down on small displays and up on retina displays. Grav's methodology for this seems logical enough, in a first sweep I appended "@2x" to the filenames, to get it working on retina displays. That worked fine. Then I wanted them to scale down as well, so I manually called the derivatives method as well. This made the images scale down on mobile, but it also put a limit on the maximum width, so that the largest source only had half the width of the original image.

I'm not sure exactly where the flawed logic is here, but it seems to be in how the combination of $alternatives and $derivatives is treated in the srcset method of the ImageMedium class (see here).

The $alternatives array should probably either be emptied if we use the derivative method manually, or srcset shouldn't work exclusively with either the $alternatives array or the $derivatives array

@rhukster rhukster added the bug label Sep 1, 2016
@rhukster
Copy link
Member

rhukster commented Sep 2, 2016

This is a bit gnarly and it's super hard to debug on my non-retina display. I really need a new computer!

@fredrikekelund
Copy link
Contributor Author

The problem should be reproducible anyway, even if the difference is hard to tell. Here's how I encountered the issue:

  1. Add a wide picture, 2500px in my case
  2. Append "@2x" to the filename
  3. Call the derivatives method in the twig template like derivatives(500, 2500, 500)
  4. Check the srcset attribute, the widest version of the image will be just 1250px, half of the original image

@rhukster
Copy link
Member

I've added a Hacktoberfest tag to see if we can get some help with this as I'm a bit stretched with other things at the moment.

@fredrikekelund
Copy link
Contributor Author

This one is hopefully addressed by my PR, so I think we just need to iron that issue out to be able to close this. Maybe this isn't that much of low hanging fruit either

@fredrikekelund
Copy link
Contributor Author

Pregenerated alternatives and alternatives that are generated using ImageMedium#derivatives now use the same underlying method, which should make things more predictable.

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