1+ var Dimension = require ( "../less/tree/dimension" ) ,
2+ Expression = require ( "../less/tree/expression" ) ,
3+ functionRegistry = require ( "./../less/functions/function-registry" ) ,
4+ path = require ( "path" ) ;
5+
6+ function imageSize ( filePathNode ) {
7+ var filePath = filePathNode . value ;
8+ var currentDirectory = filePathNode . currentFileInfo . relativeUrls ?
9+ filePathNode . currentFileInfo . currentDirectory : filePathNode . currentFileInfo . entryPath ;
10+
11+ var sizeOf = require ( 'image-size' ) ;
12+ filePath = path . join ( currentDirectory , filePath ) ;
13+ return sizeOf ( filePath ) ;
14+ }
15+
16+ var imageFunctions = {
17+ "image-size" : function ( filePathNode ) {
18+ var size = imageSize ( filePathNode ) ;
19+ return new Expression ( [
20+ new Dimension ( size . width , "px" ) ,
21+ new Dimension ( size . height , "px" )
22+ ] ) ;
23+ } ,
24+ "image-width" : function ( filePathNode ) {
25+ var size = imageSize ( filePathNode ) ;
26+ return new Dimension ( size . width , "px" ) ;
27+ } ,
28+ "image-height" : function ( filePathNode ) {
29+ var size = imageSize ( filePathNode ) ;
30+ return new Dimension ( size . height , "px" ) ;
31+ }
32+ } ;
33+
34+ functionRegistry . addMultiple ( imageFunctions ) ;
0 commit comments