diff --git a/Readme.md b/Readme.md index b8809afa..66c6ca2a 100644 --- a/Readme.md +++ b/Readme.md @@ -18,6 +18,7 @@ A [Node](https://nodejs.org/en/) module to get dimensions of any image file * TIFF * WebP * SVG +* DDS ### Upcoming diff --git a/lib/types.js b/lib/types.js index 37c9cd3c..77fd7b52 100644 --- a/lib/types.js +++ b/lib/types.js @@ -8,5 +8,6 @@ module.exports = [ 'psd', 'svg', 'tiff', - 'webp' + 'webp', + 'dds' ]; diff --git a/lib/types/dds.js b/lib/types/dds.js new file mode 100644 index 00000000..862c0460 --- /dev/null +++ b/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 +}; diff --git a/specs/images/valid/dds/sample.dds b/specs/images/valid/dds/sample.dds new file mode 100644 index 00000000..e4f09be8 Binary files /dev/null and b/specs/images/valid/dds/sample.dds differ diff --git a/specs/others.spec.js b/specs/others.spec.js index 86414832..1c5a56b2 100644 --- a/specs/others.spec.js +++ b/specs/others.spec.js @@ -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']); }); });