Skip to content

npm-dom/img

Folders and files

NameName
Last commit message
Last commit date

Latest commit

author
Azer Koçulu
Mar 12, 2017
8e57598 · Mar 12, 2017

History

13 Commits
Jun 23, 2014
Jun 23, 2014
Mar 12, 2017
Oct 25, 2014
Mar 12, 2017
Oct 25, 2014

Repository files navigation

img

Create an IMG element

Install

$ npm install npm-dom/img

Usage

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 (error, el) {
  // 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 (error, el) {
  error.message
  // => "Timeout"

}, 2000))

Optional crossOrigin parameter:

var img = require('img')

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

See test.js for more info.

Releases

No releases published

Packages

No packages published