Skip to content

Commit

Permalink
webp stub
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy committed Jul 4, 2013
1 parent 0f810d7 commit c03b131
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 3 deletions.
9 changes: 8 additions & 1 deletion lib/detector.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,20 @@ function isJPG (buffer) {
return ('ffd8' === buffer.toString('hex', 0, 2));
}

function isWebP (buffer) {
return ('RIFF' === buffer.toString('ascii', 0, 4) &&
'WEBP' === buffer.toString('ascii', 8, 12) &&
'VP8' === buffer.toString('ascii', 12, 15));
}

var typeMap = {
'bmp': isBMP,
'gif': isGIF,
'jpg': isJPG,
'png': isPNG,
'psd': isPSD,
'tiff': isTIFF
'tiff': isTIFF,
'webp': isWebP
};

module.exports = function (buffer) {
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var libpath = process.env.TEST_COV ? '../lib-cov/' : '../lib/';
var detector = require(libpath + 'detector');

var handlers = {};
['png', 'gif', 'bmp', 'psd', 'jpg'].forEach(function (type) {
['png', 'gif', 'bmp', 'psd', 'jpg', 'webp'].forEach(function (type) {
handlers[type] = require(libpath + 'types/' + type);
});

Expand Down
10 changes: 10 additions & 0 deletions lib/types/webp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = function (buffer) {
var lossless = ('L' === buffer.toString('ascii', 15, 16));
if (lossless) {

} else {

}

return {};
};
9 changes: 9 additions & 0 deletions specs/.jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"predef": [
"module",
"require",
"describe",
"beforeEach",
"it"
]
}
2 changes: 1 addition & 1 deletion specs/images.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var expect = require('expect.js');
var libpath = process.env.TEST_COV ? '../lib-cov/' : '../lib/';
var imageSize = require(libpath);

['png', 'gif', 'bmp', 'psd', 'jpg'].forEach(function (type) {
['png', 'gif', 'bmp', 'psd', 'jpg', 'webp'].forEach(function (type) {

describe(type.toUpperCase(), function() {

Expand Down
Binary file added specs/images/sample.webp
Binary file not shown.

0 comments on commit c03b131

Please sign in to comment.