Skip to content

Commit

Permalink
Added wUnits/hUnits properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaly Puzrin committed Jun 22, 2016
1 parent d063540 commit b1e2bf2
Show file tree
Hide file tree
Showing 16 changed files with 88 additions and 48 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,28 @@ var probe = require('probe-image-size');
// Get by URL
//
probe('http://example.com/image.jpg', function (err, result) {
console.log(result); // => { width: xx, height: yy, type: 'jpg', mime: 'image/jpeg' }
console.log(result); // => { width: xx, height: yy, type: 'jpg', mime: 'image/jpeg', wUnits: 'px', hUnits: 'px' }
});

// By URL with options
//
probe({ url: 'http://example.com/image.jpg', timeout: 5000 }, function (err, result) {
console.log(result); // => { width: xx, height: yy, length: zz, type: 'jpg', mime: 'image/jpeg' }
console.log(result); // => { width: xx, height: yy, length: zz, type: 'jpg', mime: 'image/jpeg', wUnits: 'px', hUnits: 'px' }
});

// With Promise
//
probe('http://example.com/image.jpg').then(function (result) {
console.log(result); // => { width: xx, height: yy, type: 'jpg', mime: 'image/jpeg' }
console.log(result); // => { width: xx, height: yy, type: 'jpg', mime: 'image/jpeg', wUnits: 'px', hUnits: 'px' }
});

// From the stream
//
var input = require('fs').createReadStream('image.jpg');

probe(input, function (err, result) {
console.log(result); // => { width: xx, height: yy, type: 'jpg', mime: 'image/jpeg' }
console.log(result);
// => { width: xx, height: yy, type: 'jpg', mime: 'image/jpeg', wUnits: 'px', hUnits: 'px' }

// terminate input, depends on stream type,
// this example is for fs streams only.
Expand All @@ -56,7 +57,7 @@ probe(input, function (err, result) {
//
var data = require('fs').readFileSync('image.jpg');

console.log(probe.sync(data)); // => { width: xx, height: yy, type: 'jpg', mime: 'image/jpeg' }
console.log(probe.sync(data)); // => { width: xx, height: yy, type: 'jpg', mime: 'image/jpeg', wUnits: 'px', hUnits: 'px' }
```


Expand All @@ -80,7 +81,9 @@ API
height: YY,
length: ZZ, // byte length of the file (if available, HTTP only)
type: ..., // image 'type' (usual file name extention)
mime: ... // mime type
mime: ..., // mime type
wUnits: 'px', // width units type ('px' by default, can be different for SVG)
hUnits: 'px', // height units type ('px' by default, can be different for SVG)
}
```

Expand Down
4 changes: 3 additions & 1 deletion lib/parse_stream/bmp.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ module.exports = function (input, _callback) {
width: data.readUInt16LE(18),
height: data.readUInt16LE(22),
type: 'bmp',
mime: 'image/bmp'
mime: 'image/bmp',
wUnits: 'px',
hUnits: 'px'
});
});

Expand Down
4 changes: 3 additions & 1 deletion lib/parse_stream/gif.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ module.exports = function (input, _callback) {
width: data.readUInt16LE(6),
height: data.readUInt16LE(8),
type: 'gif',
mime: 'image/gif'
mime: 'image/gif',
wUnits: 'px',
hUnits: 'px'
});
});

Expand Down
4 changes: 3 additions & 1 deletion lib/parse_stream/jpeg.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ function getJpegSize(parser, callback) {
width: data.readUInt16BE(3),
height: data.readUInt16BE(1),
type: 'jpg',
mime: 'image/jpeg'
mime: 'image/jpeg',
wUnits: 'px',
hUnits: 'px'
});
});
return;
Expand Down
4 changes: 3 additions & 1 deletion lib/parse_stream/png.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ module.exports = function (input, _callback) {
width: data.readUInt32BE(16),
height: data.readUInt32BE(20),
type: 'png',
mime: 'image/png'
mime: 'image/png',
wUnits: 'px',
hUnits: 'px'
});
});

Expand Down
4 changes: 3 additions & 1 deletion lib/parse_stream/psd.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ module.exports = function (input, _callback) {
width: data.readUInt32BE(12),
height: data.readUInt32BE(8),
type: 'psd',
mime: 'image/vnd.adobe.photoshop'
mime: 'image/vnd.adobe.photoshop',
wUnits: 'px',
hUnits: 'px'
});
});
});
Expand Down
4 changes: 3 additions & 1 deletion lib/parse_stream/tiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ module.exports = function (input, _callback) {
width: width,
height: height,
type: 'tiff',
mime: 'image/tiff'
mime: 'image/tiff',
wUnits: 'px',
hUnits: 'px'
});
}
});
Expand Down
12 changes: 9 additions & 3 deletions lib/parse_stream/webp.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ function parseVP8(parser, callback) {
width: data.readUInt16LE(10) & 0x3FFF,
height: data.readUInt16LE(12) & 0x3FFF,
type: 'webp',
mime: 'image/webp'
mime: 'image/webp',
wUnits: 'px',
hUnits: 'px'
});
});
}
Expand All @@ -48,7 +50,9 @@ function parseVP8L(parser, callback) {
width: (bits & 0x3FFF) + 1,
height: ((bits >> 14) & 0x3FFF) + 1,
type: 'webp',
mime: 'image/webp'
mime: 'image/webp',
wUnits: 'px',
hUnits: 'px'
});
});
}
Expand All @@ -64,7 +68,9 @@ function parseVP8X(parser, callback) {
width: ((data[10] << 16) | (data[9] << 8) | data[8]) + 1,
height: ((data[13] << 16) | (data[12] << 8) | data[11]) + 1,
type: 'webp',
mime: 'image/webp'
mime: 'image/webp',
wUnits: 'px',
hUnits: 'px'
});
});
}
Expand Down
4 changes: 3 additions & 1 deletion lib/parse_sync/bmp.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ module.exports = function (data) {
width: readUInt16LE(data, 18),
height: readUInt16LE(data, 22),
type: 'bmp',
mime: 'image/bmp'
mime: 'image/bmp',
wUnits: 'px',
hUnits: 'px'
};
};
4 changes: 3 additions & 1 deletion lib/parse_sync/gif.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ module.exports = function (data) {
width: readUInt16LE(data, 6),
height: readUInt16LE(data, 8),
type: 'gif',
mime: 'image/gif'
mime: 'image/gif',
wUnits: 'px',
hUnits: 'px'
};
};
4 changes: 3 additions & 1 deletion lib/parse_sync/jpeg.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ module.exports = function (data) {
width: readUInt16BE(data, offset + 3),
height: readUInt16BE(data, offset + 1),
type: 'jpg',
mime: 'image/jpeg'
mime: 'image/jpeg',
wUnits: 'px',
hUnits: 'px'
};
}

Expand Down
4 changes: 3 additions & 1 deletion lib/parse_sync/png.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ module.exports = function (data) {
width: readUInt32BE(data, 16),
height: readUInt32BE(data, 20),
type: 'png',
mime: 'image/png'
mime: 'image/png',
wUnits: 'px',
hUnits: 'px'
};
};
4 changes: 3 additions & 1 deletion lib/parse_sync/psd.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ module.exports = function (data) {
width: readUInt32BE(data, 6 + 12),
height: readUInt32BE(data, 6 + 8),
type: 'psd',
mime: 'image/vnd.adobe.photoshop'
mime: 'image/vnd.adobe.photoshop',
wUnits: 'px',
hUnits: 'px'
};
};
4 changes: 3 additions & 1 deletion lib/parse_sync/tiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ module.exports = function (data) {
width: width,
height: height,
type: 'tiff',
mime: 'image/tiff'
mime: 'image/tiff',
wUnits: 'px',
hUnits: 'px'
};
}
};
12 changes: 9 additions & 3 deletions lib/parse_sync/webp.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ function parseVP8(data) {
width: readUInt16LE(data, 16 + 10) & 0x3FFF,
height: readUInt16LE(data, 16 + 12) & 0x3FFF,
type: 'webp',
mime: 'image/webp'
mime: 'image/webp',
wUnits: 'px',
hUnits: 'px'
};
}

Expand All @@ -43,7 +45,9 @@ function parseVP8L(data) {
width: (bits & 0x3FFF) + 1,
height: ((bits >> 14) & 0x3FFF) + 1,
type: 'webp',
mime: 'image/webp'
mime: 'image/webp',
wUnits: 'px',
hUnits: 'px'
};
}

Expand All @@ -57,7 +61,9 @@ function parseVP8X(data) {
width: ((data[16 + 10] << 16) | (data[16 + 9] << 8) | data[16 + 8]) + 1,
height: ((data[16 + 13] << 16) | (data[16 + 12] << 8) | data[16 + 11]) + 1,
type: 'webp',
mime: 'image/webp'
mime: 'image/webp',
wUnits: 'px',
hUnits: 'px'
};
}

Expand Down
Loading

0 comments on commit b1e2bf2

Please sign in to comment.