2.0.1 • Published 3 years ago

image-batch-downloader v2.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

image-batch-download

npm version

A simple package for basic image downloading and processing.

Supported formats:

  • JPEG
  • PNG
  • WebP

Installation

With Yarn:

yarn add image-batch-downloader

Or with NPM:

npm install image-batch-downloader

How to use

Single download

The code below will download the 150 pixel image, convert it to WebP at 75% of the original quality, and resize it to 100 size.

const downloader = getDownloader();
const imageSettings: ImageSettings = {
    imageUrl: 'https://via.placeholder.com/150',
    toFormat: ImageFormat.Webp,
    quality: 75,
    outputPath: './output/my-output-image.webp',
    size: 100
};
await downloader.download(imageSettings);

Batch download

const downloader = getDownloader();
const urls = [
  'https://path-to-image-1.jpeg',
  'https://path-to-image-2.png',
  'https://path-to-image-3.webp'
];
const format = ImageFormat.Png;
const settings: ImageSettings[] = urls.map((url, index) => ({
    imageUrl: url,
    toFormat: format,
    quality: 75,
    outputPath: `./output/image-${index}.${format}`,
    size: 100
}));
await downloader.batchDownload(settings, 25);

When to use?

  • For web scraping of image-rich sites
  • To download hundreds or thousands of remote images without the server identifying the numerous requests as an attack
  • To process many images asynchronously and consuming minimal resources

Why this package?

  • Use of streams
  • Asynchronous code usage
  • Simple and easy to use API