Skip to content

Commit

Permalink
fix: used png instead of jpg to maintain picture quality
Browse files Browse the repository at this point in the history
  • Loading branch information
yashrajjain726 committed Oct 9, 2024
1 parent a37a247 commit 04f2ed5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
3 changes: 2 additions & 1 deletion mobile/lib/pages/editing/crop.page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class CropImagePage extends HookWidget {
size: 24,
),
onPressed: () async {
final croppedImage = await cropController.croppedImage();
final croppedImage = await cropController.croppedImage(
quality: FilterQuality.high);
context.pushRoute(
EditImageRoute(
asset: asset,
Expand Down
20 changes: 14 additions & 6 deletions mobile/lib/pages/editing/edit.page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import 'package:immich_mobile/routing/router.dart';
import 'package:immich_mobile/providers/album/album.provider.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:path/path.dart' as p;
import 'dart:async';
import 'dart:ui' as ui;
import 'package:flutter/rendering.dart';

/// A stateless widget that provides functionality for editing an image.
///
Expand All @@ -39,16 +42,18 @@ class EditImagePage extends ConsumerWidget {
final Completer<Uint8List> completer = Completer();
image.image.resolve(const ImageConfiguration()).addListener(
ImageStreamListener(
(ImageInfo info, bool _) {
info.image
.toByteData(format: ImageByteFormat.png)
.then((byteData) {
(ImageInfo info, bool _) async {
try {
final ByteData? byteData =
await info.image.toByteData(format: ui.ImageByteFormat.png);
if (byteData != null) {
completer.complete(byteData.buffer.asUint8List());
} else {
completer.completeError('Failed to convert image to bytes');
}
});
} catch (e) {
completer.completeError('Error converting image: $e');
}
},
onError: (exception, stackTrace) =>
completer.completeError(exception),
Expand All @@ -65,9 +70,12 @@ class EditImagePage extends ConsumerWidget {
) async {
try {
final Uint8List imageData = await _imageToUint8List(image);
// Use PNG format for lossless quality
final String fileName =
"${p.withoutExtension(asset.fileName)}_edited.png";
await ref.read(fileMediaRepositoryProvider).saveImage(
imageData,
title: "${p.withoutExtension(asset.fileName)}_edited.jpg",
title: fileName,
);
await ref.read(albumProvider.notifier).getDeviceAlbums();
Navigator.of(context).popUntil((route) => route.isFirst);
Expand Down

0 comments on commit 04f2ed5

Please sign in to comment.