mirror of
https://github.com/immich-app/immich.git
synced 2025-11-26 06:30:43 +09:00
* First test * Added translation using Weblate (French) * Translated using Weblate (German) Currently translated at 100.0% (4 of 4 strings) Translation: immich/web Translate-URL: http://familie-mach.net/projects/immich/web/de/ * Translated using Weblate (French) Currently translated at 100.0% (4 of 4 strings) Translation: immich/web Translate-URL: http://familie-mach.net/projects/immich/web/fr/ * Further testing * Further testing * Translated using Weblate (German) Currently translated at 100.0% (18 of 18 strings) Translation: immich/web Translate-URL: http://familie-mach.net/projects/immich/web/de/ * Further work * Update string file. * More strings * Automatically changed strings * Add automatically translated german file for testing purposes * Fix merge-face-selector component * Make server stats strings uppercase * Fix uppercase string * Fix some strings in jobs-panel * Fix lower and uppercase strings. Add a few additional string. Fix a few unnecessary replacements * Update german test translations * Fix typo in locales file * Change string keys * Extract more strings * Extract and replace some more strings * Update testtranslationfile * Change translation keys * Fix rebase errors * Fix one more rebase error * Remove german translation file * Co-authored-by: Daniel Dietzler <danieldietzler@users.noreply.github.com> * chore: clean up translations * chore: add new line * fix formatting * chore: fixes * fix: loading and tests --------- Co-authored-by: root <root@Blacki> Co-authored-by: admin <admin@example.com> Co-authored-by: Jason Rasmussen <jrasm91@gmail.com> Co-authored-by: Daniel Dietzler <mail@ddietzler.dev>
85 lines
3.0 KiB
Svelte
85 lines
3.0 KiB
Svelte
<script lang="ts">
|
|
import { user } from '$lib/stores/user.store';
|
|
import { handleError } from '$lib/utils/handle-error';
|
|
import { createProfileImage, type AssetResponseDto } from '@immich/sdk';
|
|
import domtoimage from 'dom-to-image';
|
|
import { onMount } from 'svelte';
|
|
import PhotoViewer from '../asset-viewer/photo-viewer.svelte';
|
|
import Button from '../elements/buttons/button.svelte';
|
|
import { NotificationType, notificationController } from './notification/notification';
|
|
import FullScreenModal from '$lib/components/shared-components/full-screen-modal.svelte';
|
|
import { t } from 'svelte-i18n';
|
|
|
|
export let asset: AssetResponseDto;
|
|
export let onClose: () => void;
|
|
|
|
let imgElement: HTMLDivElement;
|
|
|
|
onMount(() => {
|
|
imgElement.style.width = '100%';
|
|
});
|
|
|
|
const hasTransparentPixels = async (blob: Blob) => {
|
|
const img = new Image();
|
|
img.src = URL.createObjectURL(blob);
|
|
await img.decode();
|
|
const canvas = document.createElement('canvas');
|
|
canvas.width = img.width;
|
|
canvas.height = img.height;
|
|
const context = canvas.getContext('2d');
|
|
if (!context) {
|
|
throw new Error('Could not get canvas context.');
|
|
}
|
|
context.drawImage(img, 0, 0);
|
|
const imageData = context.getImageData(0, 0, canvas.width, canvas.height);
|
|
const data = imageData?.data;
|
|
if (!data) {
|
|
throw new Error('Could not get image data.');
|
|
}
|
|
for (let index = 0; index < data.length; index += 4) {
|
|
if (data[index + 3] < 255) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
};
|
|
|
|
const handleSetProfilePicture = async () => {
|
|
try {
|
|
const blob = await domtoimage.toBlob(imgElement);
|
|
if (await hasTransparentPixels(blob)) {
|
|
notificationController.show({
|
|
type: NotificationType.Error,
|
|
message: 'Profile pictures cannot have transparent pixels. Please zoom in and/or move the image.',
|
|
timeout: 3000,
|
|
});
|
|
return;
|
|
}
|
|
const file = new File([blob], 'profile-picture.png', { type: 'image/png' });
|
|
const { profileImagePath } = await createProfileImage({ createProfileImageDto: { file } });
|
|
notificationController.show({
|
|
type: NotificationType.Info,
|
|
message: $t('profile_picture_set'),
|
|
timeout: 3000,
|
|
});
|
|
$user.profileImagePath = profileImagePath;
|
|
} catch (error) {
|
|
handleError(error, $t('errors.unable_to_set_profile_picture'));
|
|
}
|
|
onClose();
|
|
};
|
|
</script>
|
|
|
|
<FullScreenModal title={$t('set_profile_picture')} width="auto" {onClose}>
|
|
<div class="flex place-items-center items-center justify-center">
|
|
<div
|
|
class="relative flex aspect-square w-[250px] overflow-hidden rounded-full border-4 border-immich-primary bg-immich-dark-primary dark:border-immich-dark-primary dark:bg-immich-primary"
|
|
>
|
|
<PhotoViewer bind:element={imgElement} {asset} />
|
|
</div>
|
|
</div>
|
|
<svelte:fragment slot="sticky-bottom">
|
|
<Button fullwidth on:click={handleSetProfilePicture}>{$t('set_as_profile_picture')}</Button>
|
|
</svelte:fragment>
|
|
</FullScreenModal>
|