thumbnail static method

Future<XImageThumbnail?> thumbnail({
  1. required String path,
  2. required int maxLongest,
})

Measures path and renders it down so its longest edge is at most maxLongest. An image already within that bound comes back at its own size rather than upscaled.

Null when the file is not a decodable image.

Implementation

static Future<XImageThumbnail?> thumbnail({
  required String path,
  required int maxLongest,
}) async {
  if (!supported) return null;
  final result = await _channel.invokeMapMethod<String, Object?>(
    'thumbnail',
    {'path': path, 'maxLongest': maxLongest},
  );
  if (result == null) return null;
  final sourceWidth = (result['sourceWidth'] as num?)?.toInt();
  final sourceHeight = (result['sourceHeight'] as num?)?.toInt();
  final width = (result['width'] as num?)?.toInt();
  final height = (result['height'] as num?)?.toInt();
  final png = result['png'] as Uint8List?;
  if (sourceWidth == null ||
      sourceHeight == null ||
      width == null ||
      height == null ||
      png == null) {
    return null;
  }
  return XImageThumbnail(
    sourceWidth: sourceWidth,
    sourceHeight: sourceHeight,
    pngBytes: png,
    width: width,
    height: height,
  );
}