image-download
v2.1.0
Published
Download an image from the given URL
Downloads
259
Maintainers
Readme
image-download
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