Normally Palatable Mango
Unleash awesomeness. Private packages, team management tools, and powerful integrations. Get started with npm Orgs »

@sgalinski/image-dimensions

1.0.0 • Public • Published

image-dimensions

This module takes a string of CSS code and looks for the occurences of image-width() and image-height() and replaces them with the dimensions of the referenced images.

Example

// styles.css
body {
    background-image: url('background.jpg');
    width: image-width('background.jpg');
    height: image-height('background.jpg');
}
// build.js
const fs = require('fs');
let css = fs.readFileSync('./foo.css', 'utf-8');
let newCss = new ImageDimensions(css, {
    imageBasePath: './images'
}).process();
fs.writeFileSync('./foo.css', newCss);
// styles.css
body {
    background-image: url('background.jpg');
    width: 213px;
    height: 160px;
}

Options

You can pass an option object as the second parameter. Right now the only option you can set is the imageBasePath. The imageBasePath will be prepended to the url that gets extracted from the imageWidth and imageHeight functions.

install

npm i @sgalinski/image-dimensions

Downloadsweekly downloads

2

version

1.0.0

license

MIT

last publish

collaborators

  • avatar
  • avatar
Report a vulnerability