From fc0b86ffe633b2e54a843fcb472880ed272ff2f3 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Mon, 11 Aug 2025 11:32:07 +0530 Subject: [PATCH 1/2] Gracefully handle image decompress error --- .../lib/ui/viewer/file/zoomable_image.dart | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart b/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart index f29315a2f2..6ff4a7ba7e 100644 --- a/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart +++ b/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart @@ -410,13 +410,18 @@ class _ZoomableImageState extends State { precacheImage( imageProvider, context, - onError: (exception, _) async { - _logger - .info(exception.toString() + ". Filename: ${_photo.displayName}"); + onError: (exception, s) async { if (exception.toString().contains( - "Codec failed to produce an image, possibly due to invalid image data", - )) { - unawaited(_loadInSupportedFormat(file)); + "Codec failed to produce an image, possibly due to invalid image data", + ) || + exception.toString().contains( + "Could not decompress image.", + )) { + unawaited(_loadInSupportedFormat(file, e)); + } else { + _logger.warning( + "Failed to load image ${_photo.displayName} with error: $exception", + ); } }, ).then((value) { @@ -471,8 +476,13 @@ class _ZoomableImageState extends State { bool _isGIF() => _photo.displayName.toLowerCase().endsWith(".gif"); - Future _loadInSupportedFormat(File file) async { - _logger.info("Compressing ${_photo.displayName} to viewable format"); + Future _loadInSupportedFormat( + File file, + Object unsupportedErr, + ) async { + _logger.info( + "Compressing ${_photo.displayName} to viewable format due to $unsupportedErr", + ); _convertToSupportedFormat = true; Uint8List? compressedFile; From 36d45c77740797eb3a8ddf9d8dc499f5bcbda791 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Mon, 11 Aug 2025 11:32:34 +0530 Subject: [PATCH 2/2] Change min Width/Height value during compress --- mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart b/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart index 6ff4a7ba7e..85e4d2fb4c 100644 --- a/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart +++ b/mobile/apps/photos/lib/ui/viewer/file/zoomable_image.dart @@ -502,7 +502,11 @@ class _ZoomableImageState extends State { quality: 85, ); } else { - compressedFile = await FlutterImageCompress.compressWithFile(file.path); + compressedFile = await FlutterImageCompress.compressWithFile( + file.path, + minHeight: 8000, + minWidth: 8000, + ); } if (compressedFile != null) {