A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/lasso-js/lasso-image below:

lasso-js/lasso-image: Get optimized image info (URL, width and height) on both the server and the client

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.

Install the plugin:

npm install lasso-image --save

Enable the plugin:

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

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.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4