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

Is it possible to specify image size and screen width separately? #129

Open
kingcw opened this issue Dec 17, 2020 · 1 comment
Open

Is it possible to specify image size and screen width separately? #129

kingcw opened this issue Dec 17, 2020 · 1 comment

Comments

@kingcw
Copy link

kingcw commented Dec 17, 2020

so basically if i do test.jpg?resize&sizes[]=300

it will generate a 300px image with screen width 300 in srcSet

<img srcset="test--300.png 300w" src="test--300.png">

This only shows this 300px image if screen width is less than 300, but usually images will only take part of a screen, like 20% of screen width, something like

<img srcset="test--300.png 1024w" src="test--300.png">

Is it possible to define image resize and screen width for srcset separately?

Thank you

@dazuaz
Copy link
Owner

dazuaz commented Dec 17, 2020

@kingcw it is not currently possible as it is, since the loader it's only reading from the width parameter.

I am not sure I understand, but you could use object-fit to make a smaller image fill the container.

This only shows this 300px image if screen width is less than 300, but usually images will only take part of a screen, like 20% of screen width, something like

This is why you should use the sizes property, when the device is a phone, images are usually 100% width, and the best image comes straight from the srcset, then let's say a viewport is a desktop and the image is 40%, then the sizes property dictates that after the Desktop viewport width.
The browser (modern) will choose the best closest image it finds in the srcset. i.e. A phone with 300px screen and 2x dpi resolution will show the first >600px with image from the srcset.

Not sure If this responds your question, but hope this helps.

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

2 participants