This commit is contained in:
Christian Beutel
2024-09-06 13:25:08 +02:00
parent b29696f326
commit 3fefab45a2
12 changed files with 193 additions and 50 deletions

View File

@@ -1,5 +1,6 @@
<script lang="ts">
import { getFileURL, readAsDataURLAsync } from "$lib/util/file_util";
import { onMount } from "svelte";
import PhotoCard from "../photo_card.svelte";
export let id: string;
@@ -42,7 +43,7 @@
document.getElementById(`${id}-photo-input`)!.click();
}
function handlePhotoSelection(files?: FileList | null) {
async function handlePhotoSelection(files?: FileList | null) {
if (!files) {
files = (
document.getElementById(`${id}-photo-input`) as HTMLInputElement
@@ -54,13 +55,25 @@
}
for (const file of files) {
let photoFile = file;
if (!file.type.startsWith("image")) {
continue;
} else if (file.type === "image/heic") {
const heic2any = (await import("heic2any")).default
photoFile = new File(
[
(await heic2any({
blob: file,
toType: "image/jpeg",
})) as Blob,
],
file.name,
);
}
if (!photoFiles) {
photoFiles = [];
}
photoFiles = [...photoFiles, file];
photoFiles = [...photoFiles, photoFile];
}
}