[Pkg-javascript-commits] [less.js] 37/38: Add image-size functions. Fixes #1378
Jonas Smedegaard
dr at jones.dk
Mon Oct 26 23:27:30 UTC 2015
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag v2.2.0
in repository less.js.
commit bac6f22a84c1c68fde531334cd0984bda988bc5f
Author: Luke Page <luke.a.page at gmail.com>
Date: Sun Jan 4 11:25:56 2015 +0000
Add image-size functions. Fixes #1378
---
lib/less-node/image-size.js | 34 ++++++++++++++++++++++++++++++++++
lib/less-node/index.js | 3 +++
package.json | 3 ++-
test/css/urls.css | 5 ++++-
test/less/urls.less | 5 ++++-
5 files changed, 47 insertions(+), 3 deletions(-)
diff --git a/lib/less-node/image-size.js b/lib/less-node/image-size.js
new file mode 100644
index 0000000..eb11835
--- /dev/null
+++ b/lib/less-node/image-size.js
@@ -0,0 +1,34 @@
+var Dimension = require("../less/tree/dimension"),
+ Expression = require("../less/tree/expression"),
+ functionRegistry = require("./../less/functions/function-registry"),
+ path = require("path");
+
+function imageSize(filePathNode) {
+ var filePath = filePathNode.value;
+ var currentDirectory = filePathNode.currentFileInfo.relativeUrls ?
+ filePathNode.currentFileInfo.currentDirectory : filePathNode.currentFileInfo.entryPath;
+
+ var sizeOf = require('image-size');
+ filePath = path.join(currentDirectory, filePath);
+ return sizeOf(filePath);
+}
+
+var imageFunctions = {
+ "image-size": function(filePathNode) {
+ var size = imageSize(filePathNode);
+ return new Expression([
+ new Dimension(size.width, "px"),
+ new Dimension(size.height, "px")
+ ]);
+ },
+ "image-width": function(filePathNode) {
+ var size = imageSize(filePathNode);
+ return new Dimension(size.width, "px");
+ },
+ "image-height": function(filePathNode) {
+ var size = imageSize(filePathNode);
+ return new Dimension(size.height, "px");
+ }
+};
+
+functionRegistry.addMultiple(imageFunctions);
\ No newline at end of file
diff --git a/lib/less-node/index.js b/lib/less-node/index.js
index d29a35e..76daa68 100644
--- a/lib/less-node/index.js
+++ b/lib/less-node/index.js
@@ -68,4 +68,7 @@ less.writeError = function (ctx, options) {
console.error(less.formatError(ctx, options));
};
+// provide image-size functionality
+require('./image-size');
+
module.exports = less;
diff --git a/package.json b/package.json
index bf15be9..adf6d7a 100644
--- a/package.json
+++ b/package.json
@@ -45,7 +45,8 @@
"request": "^2.48.0",
"mkdirp": "^0.5.0",
"source-map": "^0.1.x",
- "promise": "^6.0.1"
+ "promise": "^6.0.1",
+ "image-size": "~0.3.5"
},
"devDependencies": {
"diff": "^1.0",
diff --git a/test/css/urls.css b/test/css/urls.css
index 66b4e06..80c107c 100644
--- a/test/css/urls.css
+++ b/test/css/urls.css
@@ -66,9 +66,12 @@
uri-1: url("data:text/html,%3Ch1%3EThis%20page%20is%20100%25%20Awesome.%3C%2Fh1%3E%0A");
uri-2: url("data:text/html,%3Ch1%3EThis%20page%20is%20100%25%20Awesome.%3C%2Fh1%3E%0A");
}
-#data-uri-toobig {
+#file-functions {
uri: url('../data/data-uri-fail.png');
svg-not-base-64: url("data:image/svg+xml,%3Csvg%20height%3D%22100%22%20width%3D%22100%22%3E%0D%0A%20%20%3Ccircle%20cx%3D%2250%22%20cy%3D%2250%22%20r%3D%2240%22%20stroke%3D%22black%22%20stroke-width%3D%221%22%20fill%3D%22blue%22%20%2F%3E%0D%0A%3C%2Fsvg%3E");
+ size: 640px 430px;
+ width: 640px;
+ height: 430px;
}
#svg-functions {
background-image: url('data:image/svg+xml,%3C%3Fxml%20version%3D%221.0%22%20%3F%3E%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20version%3D%221.1%22%20width%3D%22100%25%22%20height%3D%22100%25%22%20viewBox%3D%220%200%201%201%22%20preserveAspectRatio%3D%22none%22%3E%3ClinearGradient%20id%3D%22gradient%22%20gradientUnits%3D%22userSpaceOnUse%22%20x1%3D%220%25%22%20y1%3D%220%25%22%20x2%3D%220%25%22%20y2%3D%22100%25%22%3E%3Cstop%20offset%3D%220%25%22%20stop-color%3D%22%230000 [...]
diff --git a/test/less/urls.less b/test/less/urls.less
index c0860ad..8ed07a1 100644
--- a/test/less/urls.less
+++ b/test/less/urls.less
@@ -57,9 +57,12 @@
uri-2: data-uri('../data/page.html');
}
-#data-uri-toobig {
+#file-functions {
uri: data-uri('../data/data-uri-fail.png');
svg-not-base-64: data-uri('../data/image.svg');
+ size: image-size('../data/data-uri-fail.png');
+ width: image-width('../data/data-uri-fail.png');
+ height: image-height('../data/data-uri-fail.png');
}
.add_an_import(@file_to_import) {
@import "@{file_to_import}";
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/less.js.git
More information about the Pkg-javascript-commits
mailing list