mirror of
https://github.com/immich-app/immich.git
synced 2025-01-07 00:50:23 -05:00
feat(web): Option to assign people to unassigned faces (#9773)
* added unassigned faces to people edit * svelte fix * fix format * Captialized unassigned person name, removed person id from alttext, fixed problem with multiple faces per person * Added faces to the getAssetInfo API endpoint * Updated openApi clients * Readded the photoeditor dependency * fixed lint/format * fixed photoViewer type * changes getAssetInfo.faces to only include unassigned faces * fix: bad merge * title * logic --------- Co-authored-by: Jan108 <dasJan108@gmail.com> Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
This commit is contained in:
parent
588860455f
commit
b2761b12d1
8 changed files with 211 additions and 150 deletions
BIN
mobile/openapi/lib/model/asset_response_dto.dart
generated
BIN
mobile/openapi/lib/model/asset_response_dto.dart
generated
Binary file not shown.
|
@ -7725,6 +7725,12 @@
|
||||||
"type": {
|
"type": {
|
||||||
"$ref": "#/components/schemas/AssetTypeEnum"
|
"$ref": "#/components/schemas/AssetTypeEnum"
|
||||||
},
|
},
|
||||||
|
"unassignedFaces": {
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/components/schemas/AssetFaceWithoutPersonResponseDto"
|
||||||
|
},
|
||||||
|
"type": "array"
|
||||||
|
},
|
||||||
"updatedAt": {
|
"updatedAt": {
|
||||||
"format": "date-time",
|
"format": "date-time",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
|
|
@ -194,6 +194,7 @@ export type AssetResponseDto = {
|
||||||
tags?: TagResponseDto[];
|
tags?: TagResponseDto[];
|
||||||
thumbhash: string | null;
|
thumbhash: string | null;
|
||||||
"type": AssetTypeEnum;
|
"type": AssetTypeEnum;
|
||||||
|
unassignedFaces?: AssetFaceWithoutPersonResponseDto[];
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
};
|
};
|
||||||
export type AlbumResponseDto = {
|
export type AlbumResponseDto = {
|
||||||
|
|
|
@ -2,7 +2,12 @@ import { ApiProperty } from '@nestjs/swagger';
|
||||||
import { PropertyLifecycle } from 'src/decorators';
|
import { PropertyLifecycle } from 'src/decorators';
|
||||||
import { AuthDto } from 'src/dtos/auth.dto';
|
import { AuthDto } from 'src/dtos/auth.dto';
|
||||||
import { ExifResponseDto, mapExif } from 'src/dtos/exif.dto';
|
import { ExifResponseDto, mapExif } from 'src/dtos/exif.dto';
|
||||||
import { PersonWithFacesResponseDto, mapFacesWithoutPerson, mapPerson } from 'src/dtos/person.dto';
|
import {
|
||||||
|
AssetFaceWithoutPersonResponseDto,
|
||||||
|
PersonWithFacesResponseDto,
|
||||||
|
mapFacesWithoutPerson,
|
||||||
|
mapPerson,
|
||||||
|
} from 'src/dtos/person.dto';
|
||||||
import { TagResponseDto, mapTag } from 'src/dtos/tag.dto';
|
import { TagResponseDto, mapTag } from 'src/dtos/tag.dto';
|
||||||
import { UserResponseDto, mapUser } from 'src/dtos/user.dto';
|
import { UserResponseDto, mapUser } from 'src/dtos/user.dto';
|
||||||
import { AssetFaceEntity } from 'src/entities/asset-face.entity';
|
import { AssetFaceEntity } from 'src/entities/asset-face.entity';
|
||||||
|
@ -41,6 +46,7 @@ export class AssetResponseDto extends SanitizedAssetResponseDto {
|
||||||
smartInfo?: SmartInfoResponseDto;
|
smartInfo?: SmartInfoResponseDto;
|
||||||
tags?: TagResponseDto[];
|
tags?: TagResponseDto[];
|
||||||
people?: PersonWithFacesResponseDto[];
|
people?: PersonWithFacesResponseDto[];
|
||||||
|
unassignedFaces?: AssetFaceWithoutPersonResponseDto[];
|
||||||
/**base64 encoded sha1 hash */
|
/**base64 encoded sha1 hash */
|
||||||
checksum!: string;
|
checksum!: string;
|
||||||
stackParentId?: string | null;
|
stackParentId?: string | null;
|
||||||
|
@ -116,6 +122,7 @@ export function mapAsset(entity: AssetEntity, options: AssetMapOptions = {}): As
|
||||||
livePhotoVideoId: entity.livePhotoVideoId,
|
livePhotoVideoId: entity.livePhotoVideoId,
|
||||||
tags: entity.tags?.map(mapTag),
|
tags: entity.tags?.map(mapTag),
|
||||||
people: peopleWithFaces(entity.faces),
|
people: peopleWithFaces(entity.faces),
|
||||||
|
unassignedFaces: entity.faces?.filter((face) => !face.person).map((a) => mapFacesWithoutPerson(a)),
|
||||||
checksum: entity.checksum.toString('base64'),
|
checksum: entity.checksum.toString('base64'),
|
||||||
stackParentId: withStack ? entity.stack?.primaryAssetId : undefined,
|
stackParentId: withStack ? entity.stack?.primaryAssetId : undefined,
|
||||||
stack: withStack
|
stack: withStack
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
mdiImageOutline,
|
mdiImageOutline,
|
||||||
mdiInformationOutline,
|
mdiInformationOutline,
|
||||||
mdiPencil,
|
mdiPencil,
|
||||||
|
mdiAccountOff,
|
||||||
} from '@mdi/js';
|
} from '@mdi/js';
|
||||||
import { DateTime } from 'luxon';
|
import { DateTime } from 'luxon';
|
||||||
import { createEventDispatcher, onMount } from 'svelte';
|
import { createEventDispatcher, onMount } from 'svelte';
|
||||||
|
@ -76,6 +77,7 @@
|
||||||
if (newAsset.id && !isSharedLink()) {
|
if (newAsset.id && !isSharedLink()) {
|
||||||
const data = await getAssetInfo({ id: asset.id });
|
const data = await getAssetInfo({ id: asset.id });
|
||||||
people = data?.people || [];
|
people = data?.people || [];
|
||||||
|
unassignedFaces = data?.unassignedFaces || [];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -93,6 +95,8 @@
|
||||||
$: people = asset.people || [];
|
$: people = asset.people || [];
|
||||||
$: showingHiddenPeople = false;
|
$: showingHiddenPeople = false;
|
||||||
|
|
||||||
|
$: unassignedFaces = asset.unassignedFaces || [];
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
return websocketEvents.on('on_asset_update', (assetUpdate) => {
|
return websocketEvents.on('on_asset_update', (assetUpdate) => {
|
||||||
if (assetUpdate.id === asset.id) {
|
if (assetUpdate.id === asset.id) {
|
||||||
|
@ -118,6 +122,7 @@
|
||||||
const handleRefreshPeople = async () => {
|
const handleRefreshPeople = async () => {
|
||||||
await getAssetInfo({ id: asset.id }).then((data) => {
|
await getAssetInfo({ id: asset.id }).then((data) => {
|
||||||
people = data?.people || [];
|
people = data?.people || [];
|
||||||
|
unassignedFaces = data?.unassignedFaces || [];
|
||||||
});
|
});
|
||||||
showEditFaces = false;
|
showEditFaces = false;
|
||||||
};
|
};
|
||||||
|
@ -158,11 +163,20 @@
|
||||||
|
|
||||||
<DetailPanelDescription {asset} {isOwner} />
|
<DetailPanelDescription {asset} {isOwner} />
|
||||||
|
|
||||||
{#if !isSharedLink() && people.length > 0}
|
{#if (!isSharedLink() && unassignedFaces.length > 0) || people.length > 0}
|
||||||
<section class="px-4 py-4 text-sm">
|
<section class="px-4 py-4 text-sm">
|
||||||
<div class="flex h-10 w-full items-center justify-between">
|
<div class="flex h-10 w-full items-center justify-between">
|
||||||
<h2>{$t('people').toUpperCase()}</h2>
|
<h2>{$t('people').toUpperCase()}</h2>
|
||||||
<div class="flex gap-2 items-center">
|
<div class="flex gap-2 items-center">
|
||||||
|
{#if unassignedFaces.length > 0}
|
||||||
|
<Icon
|
||||||
|
ariaLabel="Asset has unassigned faces"
|
||||||
|
title="Asset has unassigned faces"
|
||||||
|
color="currentColor"
|
||||||
|
path={mdiAccountOff}
|
||||||
|
size="24"
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
{#if people.some((person) => person.isHidden)}
|
{#if people.some((person) => person.isHidden)}
|
||||||
<CircleIconButton
|
<CircleIconButton
|
||||||
title={$t('show_hidden_people')}
|
title={$t('show_hidden_people')}
|
||||||
|
|
|
@ -1,24 +1,24 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { timeBeforeShowLoadingSpinner } from '$lib/constants';
|
import { timeBeforeShowLoadingSpinner } from '$lib/constants';
|
||||||
import { photoViewer } from '$lib/stores/assets.store';
|
|
||||||
import { getAssetThumbnailUrl, getPeopleThumbnailUrl } from '$lib/utils';
|
|
||||||
import { getPersonNameWithHiddenValue } from '$lib/utils/person';
|
import { getPersonNameWithHiddenValue } from '$lib/utils/person';
|
||||||
|
import { getPeopleThumbnailUrl } from '$lib/utils';
|
||||||
import { AssetTypeEnum, type AssetFaceResponseDto, type PersonResponseDto } from '@immich/sdk';
|
import { AssetTypeEnum, type AssetFaceResponseDto, type PersonResponseDto } from '@immich/sdk';
|
||||||
import { mdiArrowLeftThin, mdiClose, mdiMagnify, mdiPlus } from '@mdi/js';
|
import { mdiArrowLeftThin, mdiClose, mdiMagnify, mdiPlus } from '@mdi/js';
|
||||||
import { createEventDispatcher } from 'svelte';
|
import { createEventDispatcher } from 'svelte';
|
||||||
import { linear } from 'svelte/easing';
|
import { linear } from 'svelte/easing';
|
||||||
import { fly } from 'svelte/transition';
|
import { fly } from 'svelte/transition';
|
||||||
|
import { photoViewer } from '$lib/stores/assets.store';
|
||||||
import ImageThumbnail from '../assets/thumbnail/image-thumbnail.svelte';
|
import ImageThumbnail from '../assets/thumbnail/image-thumbnail.svelte';
|
||||||
import LoadingSpinner from '../shared-components/loading-spinner.svelte';
|
import LoadingSpinner from '../shared-components/loading-spinner.svelte';
|
||||||
import SearchPeople from '$lib/components/faces-page/people-search.svelte';
|
import SearchPeople from '$lib/components/faces-page/people-search.svelte';
|
||||||
import CircleIconButton from '$lib/components/elements/buttons/circle-icon-button.svelte';
|
import CircleIconButton from '$lib/components/elements/buttons/circle-icon-button.svelte';
|
||||||
|
import { zoomImageToBase64 } from '$lib/utils/people-utils';
|
||||||
import { t } from 'svelte-i18n';
|
import { t } from 'svelte-i18n';
|
||||||
|
|
||||||
export let peopleWithFaces: AssetFaceResponseDto[];
|
|
||||||
export let allPeople: PersonResponseDto[];
|
export let allPeople: PersonResponseDto[];
|
||||||
export let editedPerson: PersonResponseDto;
|
export let editedFace: AssetFaceResponseDto;
|
||||||
export let assetType: AssetTypeEnum;
|
|
||||||
export let assetId: string;
|
export let assetId: string;
|
||||||
|
export let assetType: AssetTypeEnum;
|
||||||
|
|
||||||
// loading spinners
|
// loading spinners
|
||||||
let isShowLoadingNewPerson = false;
|
let isShowLoadingNewPerson = false;
|
||||||
|
@ -39,71 +39,11 @@
|
||||||
const handleBackButton = () => {
|
const handleBackButton = () => {
|
||||||
dispatch('close');
|
dispatch('close');
|
||||||
};
|
};
|
||||||
const zoomImageToBase64 = async (face: AssetFaceResponseDto): Promise<string | null> => {
|
|
||||||
let image: HTMLImageElement | null = null;
|
|
||||||
if (assetType === AssetTypeEnum.Image) {
|
|
||||||
image = $photoViewer;
|
|
||||||
} else if (assetType === AssetTypeEnum.Video) {
|
|
||||||
const data = getAssetThumbnailUrl(assetId);
|
|
||||||
const img: HTMLImageElement = new Image();
|
|
||||||
img.src = data;
|
|
||||||
|
|
||||||
await new Promise<void>((resolve) => {
|
|
||||||
img.addEventListener('load', () => resolve());
|
|
||||||
img.addEventListener('error', () => resolve());
|
|
||||||
});
|
|
||||||
|
|
||||||
image = img;
|
|
||||||
}
|
|
||||||
if (image === null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
const {
|
|
||||||
boundingBoxX1: x1,
|
|
||||||
boundingBoxX2: x2,
|
|
||||||
boundingBoxY1: y1,
|
|
||||||
boundingBoxY2: y2,
|
|
||||||
imageWidth,
|
|
||||||
imageHeight,
|
|
||||||
} = face;
|
|
||||||
|
|
||||||
const coordinates = {
|
|
||||||
x1: (image.naturalWidth / imageWidth) * x1,
|
|
||||||
x2: (image.naturalWidth / imageWidth) * x2,
|
|
||||||
y1: (image.naturalHeight / imageHeight) * y1,
|
|
||||||
y2: (image.naturalHeight / imageHeight) * y2,
|
|
||||||
};
|
|
||||||
|
|
||||||
const faceWidth = coordinates.x2 - coordinates.x1;
|
|
||||||
const faceHeight = coordinates.y2 - coordinates.y1;
|
|
||||||
|
|
||||||
const faceImage = new Image();
|
|
||||||
faceImage.src = image.src;
|
|
||||||
|
|
||||||
await new Promise((resolve) => {
|
|
||||||
faceImage.addEventListener('load', resolve);
|
|
||||||
faceImage.addEventListener('error', () => resolve(null));
|
|
||||||
});
|
|
||||||
|
|
||||||
const canvas = document.createElement('canvas');
|
|
||||||
canvas.width = faceWidth;
|
|
||||||
canvas.height = faceHeight;
|
|
||||||
|
|
||||||
const context = canvas.getContext('2d');
|
|
||||||
if (context) {
|
|
||||||
context.drawImage(faceImage, coordinates.x1, coordinates.y1, faceWidth, faceHeight, 0, 0, faceWidth, faceHeight);
|
|
||||||
|
|
||||||
return canvas.toDataURL();
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleCreatePerson = async () => {
|
const handleCreatePerson = async () => {
|
||||||
const timeout = setTimeout(() => (isShowLoadingNewPerson = true), timeBeforeShowLoadingSpinner);
|
const timeout = setTimeout(() => (isShowLoadingNewPerson = true), timeBeforeShowLoadingSpinner);
|
||||||
const personToUpdate = peopleWithFaces.find((face) => face.person?.id === editedPerson.id);
|
|
||||||
|
|
||||||
const newFeaturePhoto = personToUpdate ? await zoomImageToBase64(personToUpdate) : null;
|
const newFeaturePhoto = await zoomImageToBase64(editedFace, assetId, assetType, $photoViewer);
|
||||||
|
|
||||||
dispatch('createPerson', newFeaturePhoto);
|
dispatch('createPerson', newFeaturePhoto);
|
||||||
|
|
||||||
|
@ -161,7 +101,7 @@
|
||||||
<h2 class="mb-8 mt-4 uppercase">{$t('all_people')}</h2>
|
<h2 class="mb-8 mt-4 uppercase">{$t('all_people')}</h2>
|
||||||
<div class="immich-scrollbar mt-4 flex flex-wrap gap-2 overflow-y-auto">
|
<div class="immich-scrollbar mt-4 flex flex-wrap gap-2 overflow-y-auto">
|
||||||
{#each showPeople as person (person.id)}
|
{#each showPeople as person (person.id)}
|
||||||
{#if person.id !== editedPerson.id}
|
{#if !editedFace.person || person.id !== editedFace.person.id}
|
||||||
<div class="w-fit">
|
<div class="w-fit">
|
||||||
<button type="button" class="w-[90px]" on:click={() => dispatch('reassign', person)}>
|
<button type="button" class="w-[90px]" on:click={() => dispatch('reassign', person)}>
|
||||||
<div class="relative">
|
<div class="relative">
|
||||||
|
|
|
@ -7,14 +7,16 @@
|
||||||
import { handleError } from '$lib/utils/handle-error';
|
import { handleError } from '$lib/utils/handle-error';
|
||||||
import { getPersonNameWithHiddenValue } from '$lib/utils/person';
|
import { getPersonNameWithHiddenValue } from '$lib/utils/person';
|
||||||
import {
|
import {
|
||||||
AssetTypeEnum,
|
|
||||||
createPerson,
|
createPerson,
|
||||||
getAllPeople,
|
getAllPeople,
|
||||||
getFaces,
|
getFaces,
|
||||||
reassignFacesById,
|
reassignFacesById,
|
||||||
|
AssetTypeEnum,
|
||||||
type AssetFaceResponseDto,
|
type AssetFaceResponseDto,
|
||||||
type PersonResponseDto,
|
type PersonResponseDto,
|
||||||
} from '@immich/sdk';
|
} from '@immich/sdk';
|
||||||
|
import { mdiAccountOff } from '@mdi/js';
|
||||||
|
import Icon from '$lib/components/elements/icon.svelte';
|
||||||
import { mdiArrowLeftThin, mdiMinus, mdiRestart } from '@mdi/js';
|
import { mdiArrowLeftThin, mdiMinus, mdiRestart } from '@mdi/js';
|
||||||
import { createEventDispatcher, onMount } from 'svelte';
|
import { createEventDispatcher, onMount } from 'svelte';
|
||||||
import { linear } from 'svelte/easing';
|
import { linear } from 'svelte/easing';
|
||||||
|
@ -23,6 +25,8 @@
|
||||||
import { NotificationType, notificationController } from '../shared-components/notification/notification';
|
import { NotificationType, notificationController } from '../shared-components/notification/notification';
|
||||||
import AssignFaceSidePanel from './assign-face-side-panel.svelte';
|
import AssignFaceSidePanel from './assign-face-side-panel.svelte';
|
||||||
import CircleIconButton from '$lib/components/elements/buttons/circle-icon-button.svelte';
|
import CircleIconButton from '$lib/components/elements/buttons/circle-icon-button.svelte';
|
||||||
|
import { zoomImageToBase64 } from '$lib/utils/people-utils';
|
||||||
|
import { photoViewer } from '$lib/stores/assets.store';
|
||||||
import { t } from 'svelte-i18n';
|
import { t } from 'svelte-i18n';
|
||||||
|
|
||||||
export let assetId: string;
|
export let assetId: string;
|
||||||
|
@ -36,7 +40,6 @@
|
||||||
let peopleWithFaces: AssetFaceResponseDto[] = [];
|
let peopleWithFaces: AssetFaceResponseDto[] = [];
|
||||||
let selectedPersonToReassign: Record<string, PersonResponseDto> = {};
|
let selectedPersonToReassign: Record<string, PersonResponseDto> = {};
|
||||||
let selectedPersonToCreate: Record<string, string> = {};
|
let selectedPersonToCreate: Record<string, string> = {};
|
||||||
let editedPerson: PersonResponseDto;
|
|
||||||
let editedFace: AssetFaceResponseDto;
|
let editedFace: AssetFaceResponseDto;
|
||||||
|
|
||||||
// loading spinners
|
// loading spinners
|
||||||
|
@ -171,11 +174,8 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleFacePicker = (face: AssetFaceResponseDto) => {
|
const handleFacePicker = (face: AssetFaceResponseDto) => {
|
||||||
if (face.person) {
|
editedFace = face;
|
||||||
editedFace = face;
|
showSelectedFaces = true;
|
||||||
editedPerson = face.person;
|
|
||||||
showSelectedFaces = true;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -209,91 +209,125 @@
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
{#each peopleWithFaces as face, index}
|
{#each peopleWithFaces as face, index}
|
||||||
{#if face.person}
|
{@const personName = face.person ? face.person?.name : 'Unassigned'}
|
||||||
<div class="relative z-[20001] h-[115px] w-[95px]">
|
<div class="relative z-[20001] h-[115px] w-[95px]">
|
||||||
<div
|
<div
|
||||||
role="button"
|
role="button"
|
||||||
tabindex={index}
|
tabindex={index}
|
||||||
class="absolute left-0 top-0 h-[90px] w-[90px] cursor-default"
|
class="absolute left-0 top-0 h-[90px] w-[90px] cursor-default"
|
||||||
on:focus={() => ($boundingBoxesArray = [peopleWithFaces[index]])}
|
on:focus={() => ($boundingBoxesArray = [peopleWithFaces[index]])}
|
||||||
on:mouseover={() => ($boundingBoxesArray = [peopleWithFaces[index]])}
|
on:mouseover={() => ($boundingBoxesArray = [peopleWithFaces[index]])}
|
||||||
on:mouseleave={() => ($boundingBoxesArray = [])}
|
on:mouseleave={() => ($boundingBoxesArray = [])}
|
||||||
>
|
>
|
||||||
<div class="relative">
|
<div class="relative">
|
||||||
{#if selectedPersonToCreate[face.id]}
|
{#if selectedPersonToCreate[face.id]}
|
||||||
|
<ImageThumbnail
|
||||||
|
curve
|
||||||
|
shadow
|
||||||
|
url={selectedPersonToCreate[face.id]}
|
||||||
|
altText={'New person'}
|
||||||
|
title={'New person'}
|
||||||
|
widthStyle={thumbnailWidth}
|
||||||
|
heightStyle={thumbnailWidth}
|
||||||
|
/>
|
||||||
|
{:else if selectedPersonToReassign[face.id]}
|
||||||
|
<ImageThumbnail
|
||||||
|
curve
|
||||||
|
shadow
|
||||||
|
url={getPeopleThumbnailUrl(selectedPersonToReassign[face.id].id)}
|
||||||
|
altText={selectedPersonToReassign[face.id].name}
|
||||||
|
title={getPersonNameWithHiddenValue(
|
||||||
|
selectedPersonToReassign[face.id].name,
|
||||||
|
selectedPersonToReassign[face.id]?.isHidden,
|
||||||
|
)}
|
||||||
|
widthStyle={thumbnailWidth}
|
||||||
|
heightStyle={thumbnailWidth}
|
||||||
|
hidden={selectedPersonToReassign[face.id].isHidden}
|
||||||
|
/>
|
||||||
|
{:else if face.person}
|
||||||
|
<ImageThumbnail
|
||||||
|
curve
|
||||||
|
shadow
|
||||||
|
url={getPeopleThumbnailUrl(face.person.id)}
|
||||||
|
altText={face.person.name}
|
||||||
|
title={getPersonNameWithHiddenValue(face.person.name, face.person.isHidden)}
|
||||||
|
widthStyle={thumbnailWidth}
|
||||||
|
heightStyle={thumbnailWidth}
|
||||||
|
hidden={face.person.isHidden}
|
||||||
|
/>
|
||||||
|
{:else}
|
||||||
|
{#await zoomImageToBase64(face, assetId, assetType, $photoViewer)}
|
||||||
<ImageThumbnail
|
<ImageThumbnail
|
||||||
curve
|
curve
|
||||||
shadow
|
shadow
|
||||||
url={selectedPersonToCreate[face.id]}
|
url="/src/lib/assets/no-thumbnail.png"
|
||||||
altText={selectedPersonToCreate[face.id]}
|
altText="Unassigned"
|
||||||
title={$t('new_person')}
|
title="Unassigned"
|
||||||
widthStyle={thumbnailWidth}
|
widthStyle="90px"
|
||||||
heightStyle={thumbnailWidth}
|
heightStyle="90px"
|
||||||
|
thumbhash={null}
|
||||||
|
hidden={false}
|
||||||
/>
|
/>
|
||||||
{:else if selectedPersonToReassign[face.id]}
|
{:then data}
|
||||||
<ImageThumbnail
|
<ImageThumbnail
|
||||||
curve
|
curve
|
||||||
shadow
|
shadow
|
||||||
url={getPeopleThumbnailUrl(selectedPersonToReassign[face.id].id)}
|
url={data === null ? '/src/lib/assets/no-thumbnail.png' : data}
|
||||||
altText={selectedPersonToReassign[face.id]?.name || selectedPersonToReassign[face.id].id}
|
altText="Unassigned"
|
||||||
title={getPersonNameWithHiddenValue(
|
title="Unassigned"
|
||||||
selectedPersonToReassign[face.id].name,
|
widthStyle="90px"
|
||||||
face.person?.isHidden,
|
heightStyle="90px"
|
||||||
)}
|
thumbhash={null}
|
||||||
widthStyle={thumbnailWidth}
|
hidden={false}
|
||||||
heightStyle={thumbnailWidth}
|
|
||||||
hidden={selectedPersonToReassign[face.id].isHidden}
|
|
||||||
/>
|
/>
|
||||||
{:else}
|
{/await}
|
||||||
<ImageThumbnail
|
|
||||||
curve
|
|
||||||
shadow
|
|
||||||
url={getPeopleThumbnailUrl(face.person.id)}
|
|
||||||
altText={face.person.name || face.person.id}
|
|
||||||
title={getPersonNameWithHiddenValue(face.person.name, face.person.isHidden)}
|
|
||||||
widthStyle={thumbnailWidth}
|
|
||||||
heightStyle={thumbnailWidth}
|
|
||||||
hidden={face.person.isHidden}
|
|
||||||
/>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{#if !selectedPersonToCreate[face.id]}
|
|
||||||
<p class="relative mt-1 truncate font-medium" title={face.person?.name}>
|
|
||||||
{#if selectedPersonToReassign[face.id]?.id}
|
|
||||||
{selectedPersonToReassign[face.id]?.name}
|
|
||||||
{:else}
|
|
||||||
{face.person?.name}
|
|
||||||
{/if}
|
|
||||||
</p>
|
|
||||||
{/if}
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="absolute -right-[5px] -top-[5px] h-[20px] w-[20px] rounded-full">
|
{#if !selectedPersonToCreate[face.id]}
|
||||||
{#if selectedPersonToCreate[face.id] || selectedPersonToReassign[face.id]}
|
<p class="relative mt-1 truncate font-medium" title={personName}>
|
||||||
<CircleIconButton
|
{#if selectedPersonToReassign[face.id]?.id}
|
||||||
color="primary"
|
{selectedPersonToReassign[face.id]?.name}
|
||||||
icon={mdiRestart}
|
|
||||||
title={$t('reset')}
|
|
||||||
size="18"
|
|
||||||
padding="1"
|
|
||||||
class="absolute left-1/2 top-1/2 translate-x-[-50%] translate-y-[-50%] transform"
|
|
||||||
on:click={() => handleReset(face.id)}
|
|
||||||
/>
|
|
||||||
{:else}
|
{:else}
|
||||||
<CircleIconButton
|
<span class={personName == 'Unassigned' ? 'dark:text-gray-500' : ''}>{personName}</span>
|
||||||
color="primary"
|
|
||||||
icon={mdiMinus}
|
|
||||||
title={$t('select_new_face')}
|
|
||||||
size="18"
|
|
||||||
padding="1"
|
|
||||||
class="absolute left-1/2 top-1/2 translate-x-[-50%] translate-y-[-50%] transform"
|
|
||||||
on:click={() => handleFacePicker(face)}
|
|
||||||
/>
|
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</p>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<div class="absolute -right-[5px] -top-[5px] h-[20px] w-[20px] rounded-full">
|
||||||
|
{#if selectedPersonToCreate[face.id] || selectedPersonToReassign[face.id]}
|
||||||
|
<CircleIconButton
|
||||||
|
color="primary"
|
||||||
|
icon={mdiRestart}
|
||||||
|
title="Reset"
|
||||||
|
size="18"
|
||||||
|
padding="1"
|
||||||
|
class="absolute left-1/2 top-1/2 translate-x-[-50%] translate-y-[-50%] transform"
|
||||||
|
on:click={() => handleReset(face.id)}
|
||||||
|
/>
|
||||||
|
{:else}
|
||||||
|
<CircleIconButton
|
||||||
|
color="primary"
|
||||||
|
icon={mdiMinus}
|
||||||
|
title="Select new face"
|
||||||
|
size="18"
|
||||||
|
padding="1"
|
||||||
|
class="absolute left-1/2 top-1/2 translate-x-[-50%] translate-y-[-50%] transform"
|
||||||
|
on:click={() => handleFacePicker(face)}
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
<div class="absolute right-[25px] -top-[5px] h-[20px] w-[20px] rounded-full">
|
||||||
|
{#if !selectedPersonToCreate[face.id] && !selectedPersonToReassign[face.id] && !face.person}
|
||||||
|
<div
|
||||||
|
class="flex place-content-center place-items-center rounded-full bg-[#d3d3d3] p-1 transition-all absolute left-1/2 top-1/2 translate-x-[-50%] translate-y-[-50%] transform"
|
||||||
|
>
|
||||||
|
<Icon color="primary" path={mdiAccountOff} ariaLabel="Just a face" size="18" />
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
@ -302,11 +336,10 @@
|
||||||
|
|
||||||
{#if showSelectedFaces}
|
{#if showSelectedFaces}
|
||||||
<AssignFaceSidePanel
|
<AssignFaceSidePanel
|
||||||
{peopleWithFaces}
|
|
||||||
{allPeople}
|
{allPeople}
|
||||||
{editedPerson}
|
{editedFace}
|
||||||
{assetType}
|
|
||||||
{assetId}
|
{assetId}
|
||||||
|
{assetType}
|
||||||
on:close={() => (showSelectedFaces = false)}
|
on:close={() => (showSelectedFaces = false)}
|
||||||
on:createPerson={(event) => handleCreatePerson(event.detail)}
|
on:createPerson={(event) => handleCreatePerson(event.detail)}
|
||||||
on:reassign={(event) => handleReassignFace(event.detail)}
|
on:reassign={(event) => handleReassignFace(event.detail)}
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
import type { Faces } from '$lib/stores/people.store';
|
import type { Faces } from '$lib/stores/people.store';
|
||||||
|
import { getAssetThumbnailUrl } from '$lib/utils';
|
||||||
|
import { AssetTypeEnum, type AssetFaceResponseDto } from '@immich/sdk';
|
||||||
import type { ZoomImageWheelState } from '@zoom-image/core';
|
import type { ZoomImageWheelState } from '@zoom-image/core';
|
||||||
|
|
||||||
const getContainedSize = (img: HTMLImageElement): { width: number; height: number } => {
|
const getContainedSize = (img: HTMLImageElement): { width: number; height: number } => {
|
||||||
|
@ -69,3 +71,61 @@ export const getBoundingBox = (
|
||||||
}
|
}
|
||||||
return boxes;
|
return boxes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const zoomImageToBase64 = async (
|
||||||
|
face: AssetFaceResponseDto,
|
||||||
|
assetId: string,
|
||||||
|
assetType: AssetTypeEnum,
|
||||||
|
photoViewer: HTMLImageElement | null,
|
||||||
|
): Promise<string | null> => {
|
||||||
|
let image: HTMLImageElement | null = null;
|
||||||
|
if (assetType === AssetTypeEnum.Image) {
|
||||||
|
image = photoViewer;
|
||||||
|
} else if (assetType === AssetTypeEnum.Video) {
|
||||||
|
const data = getAssetThumbnailUrl(assetId);
|
||||||
|
const img: HTMLImageElement = new Image();
|
||||||
|
img.src = data;
|
||||||
|
|
||||||
|
await new Promise<void>((resolve) => {
|
||||||
|
img.addEventListener('load', () => resolve());
|
||||||
|
img.addEventListener('error', () => resolve());
|
||||||
|
});
|
||||||
|
|
||||||
|
image = img;
|
||||||
|
}
|
||||||
|
if (image === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const { boundingBoxX1: x1, boundingBoxX2: x2, boundingBoxY1: y1, boundingBoxY2: y2, imageWidth, imageHeight } = face;
|
||||||
|
|
||||||
|
const coordinates = {
|
||||||
|
x1: (image.naturalWidth / imageWidth) * x1,
|
||||||
|
x2: (image.naturalWidth / imageWidth) * x2,
|
||||||
|
y1: (image.naturalHeight / imageHeight) * y1,
|
||||||
|
y2: (image.naturalHeight / imageHeight) * y2,
|
||||||
|
};
|
||||||
|
|
||||||
|
const faceWidth = coordinates.x2 - coordinates.x1;
|
||||||
|
const faceHeight = coordinates.y2 - coordinates.y1;
|
||||||
|
|
||||||
|
const faceImage = new Image();
|
||||||
|
faceImage.src = image.src;
|
||||||
|
|
||||||
|
await new Promise((resolve) => {
|
||||||
|
faceImage.addEventListener('load', resolve);
|
||||||
|
faceImage.addEventListener('error', () => resolve(null));
|
||||||
|
});
|
||||||
|
|
||||||
|
const canvas = document.createElement('canvas');
|
||||||
|
canvas.width = faceWidth;
|
||||||
|
canvas.height = faceHeight;
|
||||||
|
|
||||||
|
const context = canvas.getContext('2d');
|
||||||
|
if (context) {
|
||||||
|
context.drawImage(faceImage, coordinates.x1, coordinates.y1, faceWidth, faceHeight, 0, 0, faceWidth, faceHeight);
|
||||||
|
|
||||||
|
return canvas.toDataURL();
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in a new issue