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

Add media query support to Image #232

Closed
tomgenoni opened this issue May 6, 2019 · 4 comments
Closed

Add media query support to Image #232

tomgenoni opened this issue May 6, 2019 · 4 comments
Assignees

Comments

@tomgenoni
Copy link

tomgenoni commented May 6, 2019

This allows for different aspect ratios and/or images at different breakpoints. Couple use cases:

  1. Design calls for square image of cat at mobile, landscape version of same cat image above the small breakpoint
  2. Design calls for square image of cat at mobile, landscape image of dog above the small breakpoint

Possible API

  1. No aspect ratio
<ImageService image="321">
    ...
</ImageService>
  1. With aspect ratio
<ImageService image={{id: '321', aspectRatio: '1-1'}}>
    ...
</ImageService>
  1. With aspect ratio and media-query
<ImageService 
        image={{id: '321', aspectRatio: '1-1'}}
        imageAboveSmall={{id: '789', aspectRatio: '8-3'}}
    >
    ...
</ImageService>

Note that in #3 the HTML output must go from largest to smallest media query.

<picture>
    <source srcset="321.jpg..." media="(min-width: 701px)">
    <source srcset="321.jpg..." media="(min-width: 482px)">
    <source srcset="321.jpg...">
    <img srcset="default.jpg" alt="My default image">
</picture>```
@tomgenoni tomgenoni changed the title Add media query support to SmartImage Add media query support to Image May 13, 2019
@danoc
Copy link
Member

danoc commented May 31, 2019

Related: gatsbyjs/gatsby#13164

@wardpeet
Copy link

wardpeet commented Jun 21, 2019

We just published gatsbyjs/gatsby#13164

Successfully published:
 - [email protected]

You should be able to add an array of fluid/fixed objects to gatsby image with a media property.

To see it in action you can visit https://github.com/gatsbyjs/gatsby/blob/c9ea948f068c3ba0be11adae4570900445be0922/examples/using-gatsby-image/src/components/floating-image.js#L43-L53

@danoc
Copy link
Member

danoc commented Jun 21, 2019

Sweet, thanks @wardpeet! We'll definitely be looking at that API for inspiration.

@danoc
Copy link
Member

danoc commented Sep 16, 2019

We decided not do to this in favor of letting the consumer handle it.

@danoc danoc closed this as completed Sep 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants