Created
April 19, 2020 17:51
-
-
Save ciceropablo/d35d609fb774eb4b34fdd8f0ff843d02 to your computer and use it in GitHub Desktop.
Simple script to get width and height from image.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
fs.readFile('me.jpg', (err, data) => { | |
if (err) throw err; | |
let buf = Buffer.from(data).slice(4); | |
while(buf.length) { | |
const i = buf.readUInt16BE(0); | |
next = buf[i + 1]; | |
if (next === 0xC0 || next === 0xC1 || next === 0xC2) { | |
const width = buf.readUInt16BE(i + 7); | |
const height = buf.readUInt16BE(i + 5); | |
console.log(`${width}x${height}`); | |
} | |
buf = buf.slice(i + 2); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment