rework-sass-images
Sass/Compass image size functions written in JavaScript as a Rework plugin. Uses Imagesize to read an image's size and replaces directives in CSS with that size. Inspired by rework-imagesize and Compass Image Dimension Helpers.
Usage
var rework = ;var sass_images = ; var css = ;
Using the above JavaScript. This:
Will produce this CSS:
HiDPI support
Use special functions hidpi-image-width|height|size
to insert dimesnions divided by 2 if the image filename contains @2x
in it. For example, considering the myimage@2x.png
size is 640x480:
will produce:
Functions
Insert actual size of the image in px:
image-width('path/to/image')
-- inserts the width of the image in px;image-height('path/to/image')
-- inserts the height of the image in px;image-size('path/to/image')
-- inserts the width AND the height of the image separated by white-space;
Insert image dimensions divided by 2 only if filename contains @2x
in it. Otherwise insert real dimensions:
hidpi-image-width('path/to/image@2x')
-- inserts the width of the image divided by 2 for HiDPI images in px;hidpi-image-height('path/to/image@2x')
-- inserts the height of the image divided by 2 for HiDPI images in px;hidpi-image-size('path/to/image@2x')
-- inserts the width AND the height of the image divided by 2 for HiDPI images separated by white-space;
License
MIT