I have a centralized function to generate image tags:
function getSrcAndSrcSet($img) {
$src="/img/init/$img";
$srcset="/img/low/$img 100w, /img/medium/$img 800w, /img/high/$img 1200w";
return 'src="'.$src.'" srcset="'.$srcset.'"';
}
Various images of varying sizes might be passed to the function, most likely none of them are exactly 100px, 800px or 1200px in width.
Does it matter that the widths are inaccurate, or does it just mean that the decision on image is based on that number rather than the real image size?
Is there a way to create a srcset such that the decision is made on if a screen is a certain size (as opposed to the specific image will be a certain size)? For CSS background images I can use a media query, can I use that here? I don't think I can use the sizes
attribute because I don't know what the specific image sizes will be when the function is invoked.
question from:
https://stackoverflow.com/questions/65847553/can-i-use-srcset-with-inaccurate-image-widths 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…