Skip to content

Instantly share code, notes, and snippets.

@ciceropablo
Created April 19, 2020 17:51
Show Gist options
  • Save ciceropablo/d35d609fb774eb4b34fdd8f0ff843d02 to your computer and use it in GitHub Desktop.
Save ciceropablo/d35d609fb774eb4b34fdd8f0ff843d02 to your computer and use it in GitHub Desktop.
Simple script to get width and height from image.
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