Skip to content

Instantly share code, notes, and snippets.

@kinex
kinex / getJpegDimensions.dart
Last active April 7, 2019 06:48
Get JPEG image dimensions in Dart
// translated to Dart from a code snippet presented here:
// https://stackoverflow.com/questions/672916/how-to-get-image-height-and-width-using-java
Future<Size> getJpegDimensions(File jpegFile) async {
final f = await jpegFile.open();
Size dimension;
try {
// check for SOI marker
if (await f.readByte() != 255 || await f.readByte() != 216) {
throw new FormatException(
"SOI (Start Of Image) marker 0xff 0xd8 missing");