1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2024-11-28 08:58:49 +02:00

Fixing face orientation on rotated photos. fixes #515

This commit is contained in:
Patrik J. Braun 2022-12-15 00:20:58 +01:00
parent 586b969966
commit 9ee05c3ada
11 changed files with 48 additions and 10 deletions

View File

@ -283,19 +283,21 @@ export class MetadataLoader {
}
}
}
let orientation = OrientationTypes.TOP_LEFT;
if (exif.Orientation) {
const orientation = parseInt(
orientation = parseInt(
exif.Orientation.value as any,
10
) as number;
if (OrientationTypes.BOTTOM_LEFT < orientation) {
// noinspection JSSuspiciousNameCombination
const height = metadata.size.width;
// noinspection JSSuspiciousNameCombination
metadata.size.width = metadata.size.height;
metadata.size.height = height;
}
}
if (OrientationTypes.BOTTOM_LEFT < orientation) {
// noinspection JSSuspiciousNameCombination
const height = metadata.size.width;
// noinspection JSSuspiciousNameCombination
metadata.size.width = metadata.size.height;
metadata.size.height = height;
}
if (Config.Client.Faces.enabled) {
const faces: FaceRegion[] = [];
if (
@ -314,11 +316,32 @@ export class MetadataLoader {
x: string,
y: string
) => {
if (OrientationTypes.BOTTOM_LEFT < orientation) {
[x, y] = [y, x];
[w, h] = [h, w];
}
let swapX = 0;
let swapY = 0;
switch (orientation) {
case OrientationTypes.TOP_RIGHT:
case OrientationTypes.RIGHT_TOP:
swapX = 1;
break;
case OrientationTypes.BOTTOM_RIGHT:
case OrientationTypes.RIGHT_BOTTOM:
swapX = 1;
swapY = 1;
break;
case OrientationTypes.BOTTOM_LEFT:
case OrientationTypes.LEFT_BOTTOM:
swapY = 1;
break;
}
return {
width: Math.round(parseFloat(w) * metadata.size.width),
height: Math.round(parseFloat(h) * metadata.size.height),
left: Math.round(parseFloat(x) * metadata.size.width),
top: Math.round(parseFloat(y) * metadata.size.height),
left: Math.round(Math.abs(parseFloat(x) - swapX) * metadata.size.width),
top: Math.round(Math.abs(parseFloat(y) - swapY) * metadata.size.height),
};
};
@ -360,9 +383,12 @@ export class MetadataLoader {
if (type !== 'Face' || !name) {
continue;
}
// convert center base box to corner based box
box.left = Math.round(Math.max(0, box.left - box.width / 2));
box.top = Math.round(Math.max(0, box.top - box.height / 2));
faces.push({name, box});
}
}

View File

@ -1,4 +1,16 @@
{
"faces": [
{
"box": {
"height": 133,
"left": 468,
"top": 1090,
"width": 123
},
"name": "Joe"
}
],
"keywords": [],
"size": {
"height": 1800,
"width": 1200

Binary file not shown.

Before

Width:  |  Height:  |  Size: 243 KiB

After

Width:  |  Height:  |  Size: 247 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 240 KiB

After

Width:  |  Height:  |  Size: 244 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 241 KiB

After

Width:  |  Height:  |  Size: 246 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 242 KiB

After

Width:  |  Height:  |  Size: 246 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 241 KiB

After

Width:  |  Height:  |  Size: 245 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 246 KiB

After

Width:  |  Height:  |  Size: 250 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 246 KiB

After

Width:  |  Height:  |  Size: 250 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 245 KiB

After

Width:  |  Height:  |  Size: 249 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 246 KiB

After

Width:  |  Height:  |  Size: 250 KiB