https://github.com/lasso-js/lasso-image
Get optimized image info (URL, width and height) on both the server and the client
https://github.com/lasso-js/lasso-image
Last synced: 4 months ago
JSON representation
Get optimized image info (URL, width and height) on both the server and the client
- Host: GitHub
- URL: https://github.com/lasso-js/lasso-image
- Owner: lasso-js
- Created: 2014-10-06T00:08:11.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2018-02-06T14:23:15.000Z (over 7 years ago)
- Last Synced: 2025-06-29T04:46:14.208Z (4 months ago)
- Language: JavaScript
- Size: 22.5 KB
- Stars: 2
- Watchers: 5
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
lasso-image
================
This module provides a plugin for the [Lasso.js](https://github.com/lasso-js/lasso) 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:
```javascript
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:
```javascript
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.