JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 77
  • Score
    100M100P100Q59997F
  • License MIT

Download an image from the given URL

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

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

License

MIT © Patrick Tone