load-img

v1.0.0
loads a Image for the browser
img image load image url browser tag images htmlimagelement and 1 more...

load-img

frozen

Creates a new <img> element for the browser and provides an error-first callback for load completion.

This module has been adapted from Azer's unpublished img module, which was updated with dubious code by another author.

Install

npm install load-img --save

Example

const loadImage = require('load-img');

loadImage('images/foo.png', (err, img) => {
  if (err) throw err;
  console.log(img.width, img.height);
});

Usage

NPM

img = loadImage(src, [opt], [cb])

Creates a new <img> element with the given src property. The other parameters are optional.

You can pass opt, an object containing { crossOrigin } string. cb is a function receiving the onload or onerror event.

This function returns the created img element.

Example with crossOrigin:

const loadImage = require('load-img');

loadImage('images/foo.png', {
  crossOrigin: 'Anonymous'
}, (err, img) => {
  if (err) throw err;
  document.body.appendChild(img);
});

License

MIT, see LICENSE.md for details.

npm i load-img

Metadata

  • MIT
  • >=4.0.0
  • Matt DesLauriers
  • released 3/27/2016

Downloads

Maintainers