JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 100
  • Score
    100M100P100Q66093F
  • License Apache License v2.0

Get image info (URL, width and height) on both the server and the client

Package Exports

  • lasso-image
  • lasso-image/lasso-image-browser.js
  • lasso-image/lasso-image.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (lasso-image) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

lasso-image

This module provides a plugin for the Lasso.js and a JavaScript API that allows image info (URL, width and height) to be retrieved on both the server and the client.

Installation

Install the plugin:

npm install lasso-image --save

Enable the plugin:

require('lasso').configure({
    plugins: [
        'lasso-image',
        ...
    ]
})

Usage

The following code can be used to get image info (URL, width and height) on both the server and the client:

var lassoImage = require('lasso-image');
lassoImage.getImageInfo(require.resolve('./my-image.png'), function(err, imageInfo) {
    if (err) {
        // Handle the error
    }

    console.log('URL: ', imageInfo.url);
    console.log('width: ', imageInfo.width);
    console.log('height: ', imageInfo.height);
});

Referenced images will automatically be bundled and written and the URL for the bundled image will be returned. The result is cached (on the server) so there is no performance penalty in making subsequent calls for the same image path.