Permalink
Browse files

Added optional argument to image-size function for ignore errors. Fixes

  • Loading branch information...
1 parent 3ee813c commit 6edf4798ed361d12cb7272a26f15b270283e4022 @Panya committed Aug 27, 2012
Showing with 18 additions and 4 deletions.
  1. +12 −3 lib/functions/index.js
  2. +4 −1 test/cases/bifs.image-size.css
  3. +2 −0 test/cases/bifs.image-size.styl
View
@@ -743,13 +743,22 @@ exports.trace = function trace(){
* // => 100px
*
* @param {String} img
+ * @param {Boolean} ignoreErr
* @return {Expression}
* @api public
*/
-exports['image-size'] = function imageSize(img) {
+exports['image-size'] = function imageSize(img, ignoreErr) {
utils.assertType(img, 'string', 'img');
- var img = new Image(this, img.string);
+ try {
+ var img = new Image(this, img.string);
+ } catch (err) {
+ if (ignoreErr) {
+ return [new nodes.Unit(0), new nodes.Unit(0)];
+ } else {
+ throw err;
+ }
+ }
// Read size
img.open();
@@ -880,4 +889,4 @@ function parseUnit(str){
var n = parseInt(m[1], 10);
var type = m[2];
return new nodes.Unit(n, type);
-}
+}
@@ -6,4 +6,7 @@ body {
body {
foo: 400px 479px;
foo: 400px 479px;
-}
+}
+body {
+ foo: 0 0;
+}
@@ -14,3 +14,5 @@ body
foo image-size('tux.png')
foo image-size('tux.png')
+body
+ foo image-size('foo.png', true)

0 comments on commit 6edf479

Please sign in to comment.