2.1.0 • Published 2 years ago

image-download v2.1.0

Weekly downloads
188
License
MIT
Repository
github
Last release
2 years ago

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