question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Would you consider resizing images to be a part of the design goals of this module? It would be very convenient to keep original images in the project directory and in the importing code specify require('./images/my-photo.jpg?resize=1000px')}. From my point of view, resizing images down is a similar semantically operation as minifying with mozjpeg. What do you think?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:21 (9 by maintainers)

github_iconTop GitHub Comments

5reactions
cyrilwannercommented, Dec 16, 2018

Version v2.2.0 has just been published which now supports image resizing. If you had responsive-loader previously installed, make sure to also update it to v1.2.0 (earlier versions won’t work correctly). Also, responsive-loader requires you to either install jimp (node implementation, slower) or sharp (binary, faster).

After adding the ?resize query param, you can pass in any other available param of the responsive-loader to resize your image. Example:

const oneSize = require('./images/my-image.jpg?resize&size=300');
const multipleSizes = require('./images/my-image.jpg?resize&sizes[]=300&sizes[]=600&sizes[]=1000');

export default () => (
  <div>
    {/* Single image: */}
    <img src={oneSize.src} />

    {/* Source set with multiple sizes: */}
    <img srcSet={multipleSizes.srcSet} src={multipleSizes.src} />
  </div>
);

I hope that it works as you have expected, otherwise please tell me 😃

4reactions
cyrilwannercommented, Dec 18, 2018

So, I think that I found an improvement for both use cases.

Specifying the size with resource queries

When you want to resize single images with the query param (e.g. my-image.jpg?size=300 or my-image.jpg?sizes[]=300&sizes[]=500), you don’t need the ?resize prefix anymore (but it still works if you want it). Although if you need any other query of responsive-loader, you still need the resize prefix.

Let responsive-loader handle all JPEG and PNG images per default

If you want all images to be resized with a global config (as of your use case @denis-sokolov), you can now overwrite the default loader with the defaultImageLoader option. All JPEG and PNG images will then directly be forwarded to the responsive-loader. But as this loader is more restrictive, the query params of next-optimized-images won’t work anymore (e.g. responsive-loader can’t handle inlined images etc.). But for all other types (SVG, WEBP and GIF), img-loader will still be used and the queries are still available there.

I hope that this improves the experience for both use cases. Both changes are available in version 2.3.0 which has just been published to npm.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Free Image Resizer: Resize Photos Online | Adobe Express
Resize your photos easily with the Adobe Express free image resizer. Simply upload your pictures, change the photo size, and download your new...
Read more >
Simple Image Resizer, resize online images without losing ...
Simple Image Resizer is free, online and powerful image resizer. Resize your images, photos, scanned documents without losing quality and in a easy...
Read more >
Resize multiple images at once! - iLoveIMG
Resize multiple JPG, PNG, SVG or GIF images in seconds easily and for free. Bulk resize images by defining pixels or percentages.
Read more >
PicResize - Crop, Resize, Edit images online for free!
The original FREE picture resize and crop tool since 2005! Resize, crop, compress, add effects to your images, photos, and screenshots for free!...
Read more >
Free Online Image Resizer | Resize Photos Easily - BeFunky
It is the fastest way to edit your photos for all types of projects. Easily resize images by pixel dimensions, scale by percentages,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found