Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

776 B
Raw Blame
function looksLikeHeic(file: File): boolean {
  const ext = file.name.split('.').pop()?.toLowerCase() ?? ''
  return ext === 'heic' || ext === 'heif' || file.type === 'image/heic' || file.type === 'image/heif'
}

export async function normalizeImageFile(file: File): Promise<File> {
  if (!looksLikeHeic(file)) return file
  const { isHeic, heicTo } = await import('heic-to')
  if (!(await isHeic(file))) return file
  const blob = await heicTo({ blob: file, type: 'image/jpeg', quality: 0.92 })
  const jpegName = file.name.replace(/\.(heic|heif)$/i, '.jpg')
  return new File([blob], jpegName, { type: 'image/jpeg' })
}

export async function normalizeImageFiles(files: FileList | File[]): Promise<File[]> {
  return Promise.all(Array.from(files).map(normalizeImageFile))
}