From 6662966ab3b06e3cd9833fef6a75fe8319b2ebac Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Tue, 5 Dec 2023 21:45:56 -0500 Subject: [PATCH] Fixing crash when image is an SVG and tries to compress. --- .../amethyst/ui/components/MediaCompressor.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/MediaCompressor.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/MediaCompressor.kt index d20eb99c4..17396a8a2 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/MediaCompressor.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/MediaCompressor.kt @@ -69,11 +69,16 @@ class MediaCompressor { } } ) - } else if (contentType?.startsWith("image", true) == true && !contentType.contains("gif")) { - val compressedImageFile = Compressor.compress(applicationContext, from(uri, contentType, applicationContext)) { - default(width = 640, format = Bitmap.CompressFormat.JPEG) + } else if (contentType?.startsWith("image", true) == true && !contentType.contains("gif") && !contentType.contains("svg")) { + try { + val compressedImageFile = Compressor.compress(applicationContext, from(uri, contentType, applicationContext)) { + default(width = 640, format = Bitmap.CompressFormat.JPEG) + } + onReady(compressedImageFile.toUri(), contentType, compressedImageFile.length()) + } catch (e: Exception) { + e.printStackTrace() + onReady(uri, contentType, null) } - onReady(compressedImageFile.toUri(), contentType, compressedImageFile.length()) } else { onReady(uri, contentType, null) }