img

Create IMG element

Create an IMG element

$ npm install img

A basic usage of it would be:

var img = require('img')
var el = img('https://avatars2.githubusercontent.com/u/7551498')
document.body.appendChild(el)

You can also pass a callback, it'll be called when the img is load or failed to load:

img('https://avatars2.githubusercontent.com/u/7551498', function (errorel) {
  // image is loaded 
 
  error
  // => undefined 
 
  document.body.appendChild(el)
})

To set timeout:

var img = require('img')
var timeout = require('callback-timeout')
 
img('loads-very-slow.gif', timeout(function (errorel) {
  error.message
  // => "Timeout" 
 
}, 2000))

Optional crossOrigin parameter:

var img = require('img')
 
img('path/to/file.png', { crossOrigin: 'Anonymous' }, function(errimage) {
    console.log(image)
})

See test.js for more info.