Spaces:
Sleeping
Sleeping
| export type StudioImage = { | |
| id: string; | |
| name: string; | |
| size: string; | |
| url: string; | |
| file: File; | |
| generatedUrl?: string; | |
| generationNote?: string; | |
| selectedVariant: string; | |
| }; | |
| export function createImages(files: File[]): StudioImage[] { | |
| return files | |
| .filter((file) => file.type.startsWith('image/')) | |
| .map((file) => ({ | |
| id: crypto.randomUUID(), | |
| name: file.name, | |
| size: formatSize(file.size), | |
| url: URL.createObjectURL(file), | |
| file, | |
| selectedVariant: 'clean', | |
| })); | |
| } | |
| export function releaseImage(image: StudioImage): void { | |
| URL.revokeObjectURL(image.url); | |
| } | |
| function formatSize(bytes: number): string { | |
| if (bytes < 1024 * 1024) { | |
| return `${Math.round(bytes / 1024)} KB`; | |
| } | |
| return `${(bytes / 1024 / 1024).toFixed(1)} MB`; | |
| } | |