next-optimized-images icon indicating copy to clipboard operation
next-optimized-images copied to clipboard

Combine resizing with other options like webp

Open mastef opened this issue 6 years ago • 7 comments

Would it be possible to stack resize with another parameter like webp? Currently it seems it's either or. Right now I can only do this in css :

.webp .bgimage {
	background-image: url('../static/images/bg.jpg?webp'); // will be over-sized
}
.no-webp .bgimage {
	background-image: url('../static/images/bg.jpg?resize&size=520');
}

Ideally I'd like to do this :

.webp .bgimage {
	background-image: url('../static/images/bg.jpg?webp&resize&size=520');
}
.no-webp .bgimage {
	background-image: url('../static/images/bg.jpg?resize&size=520');
}

mastef avatar Jan 03 '20 06:01 mastef

I'm having difficulty with this as well :/

Edit: Seems like a common issue here. #120 mentions it and references relevant issues, #84 and #91. Quote from issue #120:

I'm not 100% happy with the current version for the following reasons:

  • it depends on many different webpack loaders which has led to some workarounds and many features cannot be combined because the loaders don't work well with each other. See #84, #91 for examples.

akd-io avatar Feb 03 '20 23:02 akd-io

I'm getting the same issue.

calclavia avatar Apr 15 '20 03:04 calclavia

Running into this right now.

cadekynaston avatar May 13 '20 02:05 cadekynaston

Using multiple filters would be very useful

SpicyPete avatar May 24 '20 05:05 SpicyPete

For some reason neither resizing, nor converting to webp works for me, as also mentioned in this issue. How did you guys make it work (even without combining)?

nad182 avatar Feb 20 '21 07:02 nad182

Have you tried ?resize&format=webp?

benedfit avatar Feb 20 '21 14:02 benedfit

Have you tried ?resize&format=webp?

Yes. My css file:

background-image: url('../public/images/hero-bg.png?resize&format=webp');

My next.config.js:

module.exports = withPlugins([
  [
    optimizedImages,
    {
      optimizeImagesInDev: true,
      responsive: {
        adapter: responsiveLoaderSharp,
        sizes: [300, 320, 640, 960, 1200, 1800, 2400],
        placeholder: true,
        placeholderSize: 40,
      },
    },
  ],
]);

Output in the browser after the build and deploy to netlify: image

nad182 avatar Mar 06 '21 21:03 nad182