source: trip-planner-front/node_modules/image-size/lib/types/png.js@ fa375fe

Last change on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 911 bytes
Line 
1'use strict';
2
3var pngSignature = 'PNG\r\n\x1a\n';
4var pngImageHeaderChunkName = 'IHDR';
5var pngFriedChunkName = 'CgBI'; // Used to detect "fried" png's: http://www.jongware.com/pngdefry.html
6
7function isPNG (buffer) {
8 if (pngSignature === buffer.toString('ascii', 1, 8)) {
9 var chunkName = buffer.toString('ascii', 12, 16);
10 if (chunkName === pngFriedChunkName) {
11 chunkName = buffer.toString('ascii', 28, 32);
12 }
13 if (chunkName !== pngImageHeaderChunkName) {
14 throw new TypeError('invalid png');
15 }
16 return true;
17 }
18}
19
20function calculate (buffer) {
21 if (buffer.toString('ascii', 12, 16) === pngFriedChunkName) {
22 return {
23 'width': buffer.readUInt32BE(32),
24 'height': buffer.readUInt32BE(36)
25 };
26 }
27 return {
28 'width': buffer.readUInt32BE(16),
29 'height': buffer.readUInt32BE(20)
30 };
31}
32
33module.exports = {
34 'detect': isPNG,
35 'calculate': calculate
36};
Note: See TracBrowser for help on using the repository browser.