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

Responsive images #1051

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Responsive images #1051

wants to merge 4 commits into from

Conversation

ascorbic
Copy link
Contributor

@ascorbic ascorbic commented Nov 4, 2024

Summary

Implements opinionated best practices in Astro Image, generating srcset, sizes and styles automatically.

---
import { Image } from "astro:assets"
import rocket from "./rocket.jpg"
---
<Image src={rocket} width={800} height={600} layout="responsive" />

Links

@ascorbic ascorbic mentioned this pull request Nov 4, 2024

For that reason, this RFC includes image service crop support as a goal, though it is not a blocker for the initial feature.

#### New `ImageTransform` properties
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a technical detail, but it might be the perfect time to add ImageTransform to the interfaces we allow users to extend (in packages/astro/src/types/public/extendables.ts in next) so that image services can define some other props they support.

@ascorbic
Copy link
Contributor Author

ascorbic commented Nov 7, 2024

I've updated the implementation details part of the RFC based on things I've discovered while prototyping.

@carlcs
Copy link

carlcs commented Nov 20, 2024

Hey! I‘m excited to see work being picked up again on the image components. I read the rfc and don’t really understand how values for the sizes attribute are created when „responsive“ layout is used. Is there JS being injected or how does the component know how large the image is show at different breakpoints?

@ascorbic
Copy link
Contributor Author

@carlcs It generates a sizes attribute based on the assumption that it's the full width of the screen when downsized. You'd need to pass your own if this is incorrect.

@carlcs
Copy link

carlcs commented Nov 20, 2024

@ascorbic that‘s perfect if we can still set sizes manually! You might want to change docs a bit because this part is a bit misleading.

		 * The following `<Image />` component properties should not be used with responsive images as these are automatically generated:
		 * 
		 * - `densities`
		 * - `widths`
		 * - `sizes` 		 

@ascorbic
Copy link
Contributor Author

@carlcs withastro/astro#12482

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

Successfully merging this pull request may close these issues.

3 participants