Skip to content

Instantly share code, notes, and snippets.

@danilvalov
Created February 10, 2018 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danilvalov/04f7b2bb5de91e8d02ce08eaec15cf4b to your computer and use it in GitHub Desktop.
Save danilvalov/04f7b2bb5de91e8d02ce08eaec15cf4b to your computer and use it in GitHub Desktop.
[SASS/SCSS] `image-width` and `image-height` asset functions (mixins)
const path = require('path');
const sass = require('node-sass');
const imageSizeOf = require('image-size');
module.exports = {
'image-width($imageUrl)': function (imageUrl) {
const absoluteImagePath = this.options.includePaths.split(':').pop();
const absoluteImageUrl = path.resolve(absoluteImagePath, imageUrl.getValue());
const dimensions = imageSizeOf(absoluteImageUrl);
return sass.types.Number(dimensions.width, 'px');
},
'image-height($imageUrl)': function (imageUrl) {
const absoluteImagePath = this.options.includePaths.split(':').pop();
const absoluteImageUrl = path.resolve(absoluteImagePath, imageUrl.getValue());
const dimensions = imageSizeOf(absoluteImageUrl);
return sass.types.Number(dimensions.height, 'px');
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment