Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(web): show face's border on hovered #10469

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,7 @@
"map_marker_for_images": "Map marker for images taken in {city}, {country}",
"map_marker_with_image": "Map marker with image",
"map_settings": "Map settings",
"mark_all_faces": "Show face border",
"matches": "Matches",
"media_type": "Media type",
"memories": "Memories",
Expand Down
49 changes: 42 additions & 7 deletions web/src/lib/components/asset-viewer/detail-panel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import Icon from '$lib/components/elements/icon.svelte';
import ChangeDate from '$lib/components/shared-components/change-date.svelte';
import { AppRoute, QueryParameter, timeToLoadTheMap } from '$lib/constants';
import { boundingBoxesArray } from '$lib/stores/people.store';
import { boundingBoxesArray, createBoundingBoxType, getBorderColor } from '$lib/stores/people.store';
import { locale } from '$lib/stores/preferences.store';
import { featureFlags } from '$lib/stores/server-config.store';
import { preferences, user } from '$lib/stores/user.store';
Expand All @@ -34,9 +34,12 @@
mdiImageOutline,
mdiInformationOutline,
mdiPencil,
mdiFaceRecognition,
mdiFaceMan,
} from '@mdi/js';
import { DateTime } from 'luxon';
import { t } from 'svelte-i18n';
import { onDestroy } from 'svelte';
import { slide } from 'svelte/transition';
import ImageThumbnail from '../assets/thumbnail/image-thumbnail.svelte';
import CircleIconButton from '../elements/buttons/circle-icon-button.svelte';
Expand Down Expand Up @@ -97,7 +100,22 @@
})();

$: people = asset.people || [];
$: showingHiddenPeople = false;

$: faces = showFaceBoundingBox
? people
.filter((person) => showingHiddenPeople || !person.isHidden)
.flatMap((person) =>
person.faces.map((face) => createBoundingBoxType(face, person.id, showingHiddenPeople && person.isHidden)),
)
.concat(showingHiddenPeople ? unassignedFaces.map((face) => createBoundingBoxType(face, face.id, true)) : [])
: [];

$: {
$boundingBoxesArray = faces || [];
}

let showingHiddenPeople = false;
let showFaceBoundingBox = false;

$: unassignedFaces = asset.unassignedFaces || [];

Expand All @@ -107,6 +125,10 @@
? fromDateTimeOriginal(asset.exifInfo.dateTimeOriginal, timeZone)
: fromLocalDateTime(asset.localDateTime);

onDestroy(() => {
$boundingBoxesArray = [];
});

const getMegapixel = (width: number, height: number): number | undefined => {
const megapixel = Math.round((height * width) / 1_000_000);

Expand All @@ -123,6 +145,7 @@
unassignedFaces = data?.unassignedFaces || [];
});
showEditFaces = false;
$boundingBoxesArray = faces || [];
};

const toggleAssetPath = () => (showAssetPath = !showAssetPath);
Expand Down Expand Up @@ -184,7 +207,7 @@
size="24"
/>
{/if}
{#if people.some((person) => person.isHidden)}
{#if showFaceBoundingBox || people.some((person) => person.isHidden)}
<CircleIconButton
title={$t('show_hidden_people')}
icon={showingHiddenPeople ? mdiEyeOff : mdiEye}
Expand All @@ -193,6 +216,13 @@
on:click={() => (showingHiddenPeople = !showingHiddenPeople)}
/>
{/if}
<CircleIconButton
title={$t('mark_all_faces')}
icon={showFaceBoundingBox ? mdiFaceMan : mdiFaceRecognition}
padding="1"
buttonSize="32"
on:click={() => (showFaceBoundingBox = !showFaceBoundingBox)}
/>
<CircleIconButton
title={$t('edit_people')}
icon={mdiPencil}
Expand All @@ -212,12 +242,17 @@
href="{AppRoute.PEOPLE}/{person.id}?{QueryParameter.PREVIOUS_ROUTE}={currentAlbum?.id
? `${AppRoute.ALBUMS}/${currentAlbum?.id}`
: AppRoute.PHOTOS}"
on:focus={() => ($boundingBoxesArray = people[index].faces)}
on:focus={() =>
($boundingBoxesArray = people[index].faces.map((face) => createBoundingBoxType(face, person.id, true)))}
on:blur={() => ($boundingBoxesArray = [])}
on:mouseover={() => ($boundingBoxesArray = people[index].faces)}
on:mouseleave={() => ($boundingBoxesArray = [])}
on:mouseover={() =>
($boundingBoxesArray = people[index].faces.map((face) => createBoundingBoxType(face, person.id, true)))}
on:mouseleave={() => ($boundingBoxesArray = faces)}
>
<div class="relative">
<div
class="relative border-solid border-[3px] rounded-lg border-transparent"
style:border-color={showFaceBoundingBox ? `${getBorderColor(person.id)}` : ''}
>
<ImageThumbnail
curve
shadow
Expand Down
4 changes: 2 additions & 2 deletions web/src/lib/components/asset-viewer/photo-viewer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@
/>
{#each getBoundingBox($boundingBoxesArray, $photoZoomState, $photoViewer) as boundingbox}
<div
class="absolute border-solid border-white border-[3px] rounded-lg"
style="top: {boundingbox.top}px; left: {boundingbox.left}px; height: {boundingbox.height}px; width: {boundingbox.width}px;"
class="absolute border-solid border-[3px] rounded-lg text-slate-100"
style="{boundingbox.extendedStyle}; top: {boundingbox.top}px; left: {boundingbox.left}px; height: {boundingbox.height}px; width: {boundingbox.width}px;"
/>
{/each}
</div>
Expand Down
7 changes: 4 additions & 3 deletions web/src/lib/components/faces-page/person-side-panel.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import LoadingSpinner from '$lib/components/shared-components/loading-spinner.svelte';
import { timeBeforeShowLoadingSpinner } from '$lib/constants';
import { boundingBoxesArray } from '$lib/stores/people.store';
import { boundingBoxesArray, createBoundingBoxType } from '$lib/stores/people.store';
import { websocketEvents } from '$lib/stores/websocket';
import { getPeopleThumbnailUrl, handlePromiseError } from '$lib/utils';
import { handleError } from '$lib/utils/handle-error';
Expand Down Expand Up @@ -207,8 +207,9 @@
role="button"
tabindex={index}
class="absolute left-0 top-0 h-[90px] w-[90px] cursor-default"
on:focus={() => ($boundingBoxesArray = [peopleWithFaces[index]])}
on:mouseover={() => ($boundingBoxesArray = [peopleWithFaces[index]])}
on:focus={() => ($boundingBoxesArray = [createBoundingBoxType(peopleWithFaces[index], face.id, true)])}
on:mouseover={() =>
($boundingBoxesArray = [createBoundingBoxType(peopleWithFaces[index], face.id, true)])}
on:mouseleave={() => ($boundingBoxesArray = [])}
>
<div class="relative">
Expand Down
24 changes: 23 additions & 1 deletion web/src/lib/stores/people.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,26 @@ export interface Faces {
boundingBoxY2: number;
}

export const boundingBoxesArray = writable<Faces[]>([]);
interface BoundingBoxStyle {
color: string;
isSelected: boolean;
}

export interface BoundingBoxType {
boundingBoxStyle: BoundingBoxStyle;
faces: Faces;
}

export function getBorderColor(personId: string): string {
return `#${personId.slice(-6)}`;
}

function createBoundingBoxStyle(personId: string, isSelected: boolean): BoundingBoxStyle {
return { color: getBorderColor(personId), isSelected };
}

export function createBoundingBoxType(faces: Faces, personId: string, isSelected: boolean): BoundingBoxType {
return { boundingBoxStyle: createBoundingBoxStyle(personId, isSelected), faces };
}

export const boundingBoxesArray = writable<BoundingBoxType[]>([]);
13 changes: 10 additions & 3 deletions web/src/lib/utils/people-utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Faces } from '$lib/stores/people.store';
import type { BoundingBoxType } from '$lib/stores/people.store';
import { getAssetThumbnailUrl } from '$lib/utils';
import { AssetTypeEnum, type AssetFaceResponseDto } from '@immich/sdk';
import type { ZoomImageWheelState } from '@zoom-image/core';
Expand All @@ -15,14 +15,15 @@ const getContainedSize = (img: HTMLImageElement): { width: number; height: numbe
};

export interface boundingBox {
extendedStyle: string;
top: number;
left: number;
width: number;
height: number;
}

export const getBoundingBox = (
faces: Faces[],
fromBoundingBoxesArray: BoundingBoxType[],
zoom: ZoomImageWheelState,
photoViewer: HTMLImageElement | null,
): boundingBox[] => {
Expand All @@ -36,7 +37,12 @@ export const getBoundingBox = (

const { width, height } = getContainedSize(photoViewer);

for (const face of faces) {
for (const fromBoundingBox of fromBoundingBoxesArray) {
const extendedStyle = fromBoundingBox.boundingBoxStyle.isSelected
? `border-color: #ffffff; background: ${fromBoundingBox.boundingBoxStyle.color}; opacity: 0.6`
: `border-color: ${fromBoundingBox.boundingBoxStyle.color}`;

const face = fromBoundingBox.faces;
/*
*
* Create the coordinates of the box based on the displayed image.
Expand All @@ -63,6 +69,7 @@ export const getBoundingBox = (
};

boxes.push({
extendedStyle,
top: Math.round(coordinates.y1),
left: Math.round(coordinates.x1),
width: Math.round(coordinates.x2 - coordinates.x1),
Expand Down
Loading