Skip to content

Commit

Permalink
Add basic support for the DDS file format
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Vergenz authored and Aditya committed May 15, 2017
1 parent 287d8ea commit 5223e97
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions Readme.md
Expand Up @@ -18,6 +18,7 @@ A [Node](https://nodejs.org/en/) module to get dimensions of any image file
* TIFF
* WebP
* SVG
* DDS

### Upcoming

Expand Down
3 changes: 2 additions & 1 deletion lib/types.js
Expand Up @@ -8,5 +8,6 @@ module.exports = [
'psd',
'svg',
'tiff',
'webp'
'webp',
'dds'
];
18 changes: 18 additions & 0 deletions lib/types/dds.js
@@ -0,0 +1,18 @@
'use strict';

function isDDS(buffer){
return buffer.readUInt32LE(0) === 0x20534444;
}

function calculate(buffer){
// read file resolution metadata
return {
'height': buffer.readUInt32LE(12),
'width': buffer.readUInt32LE(16)
};
}

module.exports = {
'detect': isDDS,
'calculate': calculate
};
Binary file added specs/images/valid/dds/sample.dds
Binary file not shown.
2 changes: 1 addition & 1 deletion specs/others.spec.js
Expand Up @@ -72,6 +72,6 @@ describe('Callback function', function () {

describe('.types property', function () {
it('should expose supported file types', function() {
expect(imageSize.types).to.eql(['bmp', 'gif', 'jpg', 'png', 'psd', 'svg', 'tiff', 'webp']);
expect(imageSize.types).to.eql(['bmp', 'gif', 'jpg', 'png', 'psd', 'svg', 'tiff', 'webp', 'dds']);
});
});

0 comments on commit 5223e97

Please sign in to comment.