I am working with an img
tag that is placed inside a container with 30 pixels of horizontal padding. The current setup displays a 640-pixel wide image if the screen width is greater than or equal to 670 pixels, and a 320-pixel wide image otherwise:
<img srcset="TestImage320.png 320w, TestImage640.png 640w"
sizes="(max-width: 669px) 320px, 640px"
src="TestImage320.png">
However, I have noticed that the 640-pixel image is just a manually upscaled version of the 320-pixel image. Is there a way to achieve the same result without having to create (and make users download) the larger image?
Currently, my approach involves switching between src="TestImage320.png"
and src="TestImage640.png"
based on available width. Instead, I would like to stick with src="TestImage320.png"
and choose between setting style="width: 320px"
and style="width: 640px"
. How can I accomplish this desired effect (or something similar)?