image icon indicating copy to clipboard operation
image copied to clipboard

Set height with sizes attribute

Open wokalek opened this issue 2 years ago • 1 comments

Usecase: you have long image (width > height) and you need square to thumbnail, eg:

image

You cant do object: cover, because settings sizes="'xs:72px sm:102px md:114px lg:138px xl:160px xxl:184px 2xl:552px'" do this:

image


image

It's blurry and not 138x138. But if you specified fit="cover", it doesn't help, because getSizes receives already counted 138x82 as width/height

So, what if you can provide height in sizes property xs:72x72 sm:102x102 md:114x114 lg:138x138 xl:160x160 xl:184x184 2xl:552x552?

And with this fit modifier will work!

wokalek avatar Jun 29 '23 00:06 wokalek

Workaround:

const img = useImage()
const sizes = img.getSizes("/i/splash.jpg", { sizes: "500px sm:600px md:800px lg:1200px", modifiers: { quaility: 100 } })
const srcset = sizes.srcset.replace(/w_\d+/g, match => match.replace('w_', 'h_'))

Remove sizes and use srcset on your NuxtImg

OhB00 avatar Dec 31 '24 17:12 OhB00