Package Exports
- image-download
- image-download/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (image-download) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
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