New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

image-promise

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

image-promise

Load an image and return a promise in the browser, in 0.4KB

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.9K
decreased by-25.73%
Maintainers
1
Weekly downloads
 
Created
Source

image-promise

Load an image and return a promise in the browser, in 0.4KB, no dependencies

gzipped size Travis build status gzipped size

Install

npm install --save image-promise
import loadImage from 'image-promise';

If you don't use node/babel, include this:

<script src="dist/image-promise.browser.js"></script>

It uses the ES2015 window.Promise, so if you need to support older browsers you need a polyfill.

Usage

You can load a single image from its URL:

loadImage('img.jpg').then(function (img) {
	console.log('Image loaded!', img);
}).catch(function () {
	console.error('Image failed to load :(');
});

image-promise also caches the generated <img> tags so successive calls with the same exact src string will return the same <img> tag and be resolve at the same time as the first one.

Because are <img> are cached internally, if you want to uncache and unload them from memory, call the unload method on the same src:

loadImage.unload('img.jpg');

Dependencies

None! But you might need to polyfill window.Promise

License

MIT © Federico Brigante

Keywords

FAQs

Package last updated on 03 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc