Skip to content

@mega-yfue/eufy-sdk / jpegGeometry

Function: jpegGeometry()

ts
function jpegGeometry(jpeg): 
  | {
  height: number;
  width: number;
}
  | undefined;

The geometry a JPEG declares in its own frame header (SOFn), or undefined when it carries none.

Walks the marker segments from the SOI rather than searching for the marker bytes: a 0xffc0 pair occurs inside quantization tables and entropy-coded data, and the first one found there would answer with two bytes of image content. Every SOFn puts precision, then height, then width at the same offset past its length field, so one read serves all of them. Any number of 0xff fill bytes may precede a marker, and the standalone markers carry no length to skip by — both are what a naive walk gets wrong, and either would make a perfectly good image read as having no geometry.

Decoding the image (the jpeg-js path the v2 thumbnail decoder needs) would answer the same question, but it is synchronous pure JS over every pixel: this needs a dozen bytes of header, so it reads them.

Parameters

jpeg

Buffer

Returns

| { height: number; width: number; } | undefined

Independent and unofficial. Not affiliated with, endorsed by, or sponsored by Anker Innovations, Anker eufy, or eufy. "Anker eufy", "eufy" and "Anker" are trademarks of their respective owners. Use responsibly — rapid or failed logins can trigger captcha or temporary cooldowns.