Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mob][photos] Fix oversized face images in avatar widgets

ashilkn6701f5bede73
diff --git a/mobile/apps/photos/lib/ui/sharing/user_avator_widget.dart b/mobile/apps/photos/lib/ui/sharing/user_avator_widget.dart
index 5e1ac8510e..f6615f2f60 100644
--- a/mobile/apps/photos/lib/ui/sharing/user_avator_widget.dart
+++ b/mobile/apps/photos/lib/ui/sharing/user_avator_widget.dart
@@ -98,6 +98,8 @@ class _UserAvatarWidgetState extends State<UserAvatarWidget> {
@override
Widget build(BuildContext context) {
final double size = getAvatarSize(widget.type);
+ final int pixelSize =
+ (size * MediaQuery.devicePixelRatioOf(context)).toInt();
return _personID != null
? Container(
padding:
@@ -127,6 +129,7 @@ class _UserAvatarWidgetState extends State<UserAvatarWidget> {
? PersonFaceWidget(
key: ValueKey('$personID-$lastSyncTimeForKey'),
personId: personID,
+ size: pixelSize,
onErrorCallback: () {
if (mounted) {
setState(() {
diff --git a/mobile/apps/photos/lib/ui/viewer/people/file_face_widget.dart b/mobile/apps/photos/lib/ui/viewer/people/file_face_widget.dart
index 872630fcc0..95f3a97e97 100644
--- a/mobile/apps/photos/lib/ui/viewer/people/file_face_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/people/file_face_widget.dart
@@ -23,6 +23,10 @@ class FileFaceWidget extends StatefulWidget {
final bool useFullFile;
final bool thumbnailFallback;
+ /// Target display size in physical pixels (logical size Γ— devicePixelRatio).
+ /// When provided, the image will be decoded at this size to reduce memory usage.
+ final int? size;
+
const FileFaceWidget(
this.file, {
this.face,
@@ -30,6 +34,7 @@ class FileFaceWidget extends StatefulWidget {
this.clusterID,
this.useFullFile = true,
this.thumbnailFallback = false,
+ this.size,
super.key,
});
@@ -63,7 +68,12 @@ class _FileFaceWidgetState extends State<FileFaceWidget> {
future: faceCropFuture,
builder: (context, snapshot) {
if (snapshot.hasData) {
- final ImageProvider imageProvider = MemoryImage(snapshot.data!);
+ final ImageProvider imageProvider = widget.size != null
+ ? Image.memory(
+ snapshot.data!,
+ cacheWidth: widget.size,
+ ).image
+ : MemoryImage(snapshot.data!);
return Stack(
fit: StackFit.expand,
children: [
diff --git a/mobile/apps/photos/lib/ui/viewer/people/person_face_widget.dart b/mobile/apps/photos/lib/ui/viewer/people/person_face_widget.dart
index 8068b4a7b7..b02abc22b9 100644
--- a/mobile/apps/photos/lib/ui/viewer/people/person_face_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/people/person_face_widget.dart
@@ -24,6 +24,10 @@ class PersonFaceWidget extends StatefulWidget {
final VoidCallback? onErrorCallback;
final bool keepAlive;
+ /// Target display size in physical pixels (logical size Γ— devicePixelRatio).
+ /// When provided, the image will be decoded at this size to reduce memory usage.
+ final int? size;
+
// PersonFaceWidget constructor checks that both personId and clusterID are not null
// and that the file is not null
const PersonFaceWidget({
@@ -32,6 +36,7 @@ class PersonFaceWidget extends StatefulWidget {
this.useFullFile = true,
this.onErrorCallback,
this.keepAlive = false,
+ this.size,
super.key,
}) : assert(
personId != null || clusterID != null,
@@ -88,7 +93,15 @@ class _PersonFaceWidgetState extends State<PersonFaceWidget>
future: faceCropFuture,
builder: (context, snapshot) {
if (snapshot.hasData && snapshot.data != null) {
- final ImageProvider imageProvider = MemoryImage(snapshot.data!);
+ // Only cacheWidth (not cacheHeight) to preserve aspect ratio.
+ // Face crops are typically portrait, so constraining width ensures
+ // sufficient height for BoxFit.cover without upscaling.
+ final ImageProvider imageProvider = widget.size != null
+ ? Image.memory(
+ snapshot.data!,
+ cacheWidth: widget.size,
+ ).image
+ : MemoryImage(snapshot.data!);
return Stack(
fit: StackFit.expand,
children: [