image-resource
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Image Resource

Image resource provide a simple way to load images using promises, and patch IE naturalWidth and naturalHeight for SVG.

Example:

ImageResource.load('my-image.svg').then((image) => {
  document.body.append(image.image);
  console.log(image.naturalWidth, image.naturalHeight);
});

Documentation

load(sourcestring)Promise<ImageResource>;

Load an image from an url. Return a promise resolved when image loading is complete.

addEventListener(typestring, listenerEventListenerOrEventListenerObject, useCapture?: boolean)void;
dispatchEvent(eventEvent)boolean;
removeEventListener(typestring, listenerEventListenerOrEventListenerObject, useCapture?: boolean)void;

It's possible to bind events like any other EventTarget.

readonly naturalWidthnumber;
readonly naturalHeightnumber;

It's possible to read the natural size of the image (working on IE with SVG too).

public imageHTMLImageElement;

Finally, it's possible to acces to the original Image element through imageResource.image

Readme

Keywords

none

Package Sidebar

Install

npm i image-resource

Weekly Downloads

6

Version

1.0.1

License

ISC

Last publish

Collaborators

  • lifaon74