[mob][photos] Fix issues with face thumbnail (#1523)

## Description

See commits.
This commit is contained in:
Laurens Priem 2024-04-23 11:21:38 +05:30 committed by GitHub
commit dad427a498
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 34 deletions

View file

@ -55,6 +55,7 @@ class _FaceWidgetState extends State<FaceWidget> {
builder: (context, snapshot) { builder: (context, snapshot) {
if (snapshot.hasData) { if (snapshot.hasData) {
final ImageProvider imageProvider = MemoryImage(snapshot.data!); final ImageProvider imageProvider = MemoryImage(snapshot.data!);
return GestureDetector( return GestureDetector(
onTap: () async { onTap: () async {
if (widget.editMode) return; if (widget.editMode) return;
@ -263,32 +264,12 @@ class _FaceWidgetState extends State<FaceWidget> {
}, },
child: Column( child: Column(
children: [ children: [
Container( SizedBox(
height: 60,
width: 60, width: 60,
decoration: ShapeDecoration( height: 60,
shape: RoundedRectangleBorder( child: CroppedFaceImageView(
borderRadius: enteFile: widget.file,
const BorderRadius.all(Radius.elliptical(16, 12)), face: widget.face,
side: widget.highlight
? BorderSide(
color: getEnteColorScheme(context).primary700,
width: 2.0,
)
: BorderSide.none,
),
),
child: ClipRRect(
borderRadius:
const BorderRadius.all(Radius.elliptical(16, 12)),
child: SizedBox(
width: 60,
height: 60,
child: CroppedFaceImageView(
enteFile: widget.file,
face: widget.face,
),
),
), ),
), ),
const SizedBox(height: 8), const SizedBox(height: 8),

View file

@ -38,7 +38,8 @@ class CroppedFaceImageView extends StatelessWidget {
builder: (context, snapshot) { builder: (context, snapshot) {
if (snapshot.hasData) { if (snapshot.hasData) {
return LayoutBuilder( return LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) { builder: ((context, constraints) {
final double imageAspectRatio = enteFile.width / enteFile.height;
final Image image = snapshot.data!; final Image image = snapshot.data!;
final double viewWidth = constraints.maxWidth; final double viewWidth = constraints.maxWidth;
@ -51,14 +52,13 @@ class CroppedFaceImageView extends StatelessWidget {
final double relativeFaceCenterY = final double relativeFaceCenterY =
faceBox.yMin + faceBox.height / 2; faceBox.yMin + faceBox.height / 2;
const double desiredFaceHeightRelativeToWidget = 7 / 10; const double desiredFaceHeightRelativeToWidget = 8 / 10;
final double scale = final double scale =
(1 / faceBox.height) * desiredFaceHeightRelativeToWidget; (1 / faceBox.height) * desiredFaceHeightRelativeToWidget;
final double widgetCenterX = viewWidth / 2; final double widgetCenterX = viewWidth / 2;
final double widgetCenterY = viewHeight / 2; final double widgetCenterY = viewHeight / 2;
final double imageAspectRatio = enteFile.width / enteFile.height;
final double widgetAspectRatio = viewWidth / viewHeight; final double widgetAspectRatio = viewWidth / viewHeight;
final double imageToWidgetRatio = final double imageToWidgetRatio =
imageAspectRatio / widgetAspectRatio; imageAspectRatio / widgetAspectRatio;
@ -68,16 +68,15 @@ class CroppedFaceImageView extends StatelessWidget {
double offsetY = double offsetY =
(widgetCenterY - relativeFaceCenterY * viewHeight) * scale; (widgetCenterY - relativeFaceCenterY * viewHeight) * scale;
if (imageAspectRatio > widgetAspectRatio) { if (imageAspectRatio < widgetAspectRatio) {
// Landscape Image: Adjust offsetX more conservatively // Landscape Image: Adjust offsetX more conservatively
offsetX = offsetX * imageToWidgetRatio; offsetX = offsetX * imageToWidgetRatio;
} else { } else {
// Portrait Image: Adjust offsetY more conservatively // Portrait Image: Adjust offsetY more conservatively
offsetY = offsetY / imageToWidgetRatio; offsetY = offsetY / imageToWidgetRatio;
} }
return ClipRRect(
return ClipRect( borderRadius: const BorderRadius.all(Radius.elliptical(16, 12)),
clipBehavior: Clip.antiAlias,
child: Transform.translate( child: Transform.translate(
offset: Offset( offset: Offset(
offsetX, offsetX,
@ -89,7 +88,7 @@ class CroppedFaceImageView extends StatelessWidget {
), ),
), ),
); );
}, }),
); );
} else { } else {
if (snapshot.hasError) { if (snapshot.hasError) {
@ -110,7 +109,7 @@ class CroppedFaceImageView extends StatelessWidget {
} }
final imageData = await ioFile.readAsBytes(); final imageData = await ioFile.readAsBytes();
final image = Image.memory(imageData, fit: BoxFit.cover); final image = Image.memory(imageData, fit: BoxFit.contain);
return image; return image;
} }