ui: Add HEIC/HEIF image support (#24137)
* Add boilerplate for file types * Add heic-to and implement conversion * Load heic library from CDN * Use jpg instead of png for conversion * Move const to constants file
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { isSvgMimeType, svgBase64UrlToPngDataURL } from './svg-to-png';
|
||||
import { isWebpMimeType, webpBase64UrlToPngDataURL } from './webp-to-png';
|
||||
import { heicFileToJpegDataURL, isHeicMimeType } from './heic-to-jpeg';
|
||||
import { FileTypeCategory } from '$lib/enums';
|
||||
import { SETTINGS_KEYS } from '$lib/constants';
|
||||
import { modelsStore } from '$lib/stores/models.svelte';
|
||||
@@ -68,7 +69,7 @@ export async function processFilesToChatUploaded(
|
||||
if (getFileTypeCategory(file.type) === FileTypeCategory.IMAGE) {
|
||||
let preview = await readFileAsDataURL(file);
|
||||
|
||||
// Normalize SVG and WebP to PNG in previews
|
||||
// Normalize SVG and WebP to PNG, and HEIC to compressed JPEG, in previews
|
||||
if (isSvgMimeType(file.type)) {
|
||||
try {
|
||||
preview = await svgBase64UrlToPngDataURL(preview);
|
||||
@@ -81,6 +82,13 @@ export async function processFilesToChatUploaded(
|
||||
} catch (err) {
|
||||
console.error('Failed to convert WebP to PNG:', err);
|
||||
}
|
||||
} else if (isHeicMimeType(file.type)) {
|
||||
try {
|
||||
preview = await heicFileToJpegDataURL(file);
|
||||
} catch (err) {
|
||||
console.error('Failed to convert HEIC to PNG:', err);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
results.push({ ...base, preview });
|
||||
|
||||
Reference in New Issue
Block a user