probeSize method

  1. @override
Future<(int, int)> probeSize(
  1. Uint8List bytes
)
override

Read just the pixel dimensions of bytes from the image header, without decoding the pixels. Returns (width, height).

Implementation

@override
Future<(int, int)> probeSize(Uint8List bytes) async {
  final blob = web.Blob(
    [bytes.toJS].toJS,
    web.BlobPropertyBag(type: 'application/octet-stream'),
  );
  final web.ImageBitmap bitmap;
  try {
    // Oriented dimensions, to match iOS/Android and the compressed output.
    bitmap = await web.window
        .createImageBitmap(
          blob,
          web.ImageBitmapOptions(imageOrientation: 'from-image'),
        )
        .toDart;
  } catch (e) {
    throw DecodeError('Could not read image: $e');
  }
  final size = (bitmap.width, bitmap.height);
  bitmap.close();
  return size;
}