image-download
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

image-download

image-download build code size

Download an image from the given URL.

Install

npm install --save image-download

Usage

const fs = require("fs");
const imageDownload = require("image-download");
const imageType = require("image-type");

imageDownload("https://www.fillmurray.com/g/200/300").then((buffer) => {
  const type = imageType(buffer);

  fs.writeFile("bill-murray." + type.ext, buffer, (err) =>
    console.log(err ? err : "done!");
  );
});

imageDownload.withType("https://www.placecage.com/gif/200/300").then({buffer, type} => {
  console.log(type);
  //=> {ext: 'gif', mime: 'image/gif'}

  fs.writeFile(`nicolas-cage.${type.ext}`, buffer, (err) =>
    console.log(err ? err : "done!");
  );
});

API

imageDownload(url)

Returns a Promise. The fulfilled value is a Buffer of the image.

Or null if the URL is bad or does not have an image.

url

Type: string

Related

License

MIT © Patrick Tone

Package Sidebar

Install

npm i image-download

Weekly Downloads

36

Version

2.1.0

License

MIT

Unpacked Size

4.33 kB

Total Files

4

Last publish

Collaborators

  • the-pat