Nostalgic Primordial Monster
    Wondering what’s next for npm?Check out our public roadmap! »

    @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

    1

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    10.2 kB

    Total Files

    5

    Last publish

    Collaborators