Merge pull request #7 from DieLustigenTierwesen/copilot/sub-pr-6

Offload image compression to background isolate
This commit is contained in:
Lukas Müllner 2026-03-09 06:23:17 +01:00 committed by GitHub
commit f470b0d9a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -113,6 +113,12 @@ class StorageService {
static Future<Uint8List> _compressImage(File source) async { static Future<Uint8List> _compressImage(File source) async {
final bytes = await source.readAsBytes(); final bytes = await source.readAsBytes();
return compute(_compressImageBytes, bytes);
}
/// Performs CPU-intensive image decoding, resizing, and JPEG encoding.
/// Runs in a background isolate via [compute] to avoid blocking the UI thread.
static Uint8List _compressImageBytes(Uint8List bytes) {
final decoded = img.decodeImage(bytes); final decoded = img.decodeImage(bytes);
if (decoded == null) { if (decoded == null) {
throw Exception('Invalid image file.'); throw Exception('Invalid image file.');