From ab4a07a40f7525376b2d9d3acc90248e2e6f5c7e Mon Sep 17 00:00:00 2001 From: Tiel Coder Date: Sat, 21 Nov 2026 02:36:59 +0000 Subject: [PATCH] fix(editor): decode camera raws to PNG so previews and thumbs render ImageMagick 7 in the app image refuses to write TIFF from its LibRaw coder ("no encode delegate for this image format `NEF'"), so every RAW thumbnail, preview and bridge proxy returned 415. The editor showed "The preview could not be prepared" and the advanced editor had no editable proxy to open. PNG is decoded reliably by the same build and read back by sharp. --- src/lib/photo-render.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/lib/photo-render.ts b/src/lib/photo-render.ts index 24cf84b..04aab7a 100644 --- a/src/lib/photo-render.ts +++ b/src/lib/photo-render.ts @@ -2,9 +2,11 @@ * Full-resolution photo rendering. * * JPEG/PNG/WebP/TIFF/HEIC originals go through sharp. Camera RAW files are - * decoded by ImageMagick's LibRaw delegate into a temporary TIFF, then sharp + * decoded by ImageMagick's LibRaw delegate into a temporary PNG, then sharp * applies the same tone/colour recipe as the browser preview, crops and encodes - * the final JPEG. The original is read-only throughout. + * the final JPEG. PNG is used rather than TIFF because ImageMagick 7 refuses + * to write TIFF from its RAW coder ("no encode delegate for this image format + * `NEF'"). The original is read-only throughout. */ import { execFile } from "node:child_process"; @@ -28,12 +30,12 @@ export class PhotoRenderError extends Error { } } -async function rawToTiff( +async function rawToPng( filePath: string, maxDimension?: number, ): Promise<{ path: string; cleanup: () => Promise }> { const directory = await mkdtemp(path.join(tmpdir(), "glenloch-raw-")); - const output = path.join(directory, "decoded.tiff"); + const output = path.join(directory, "decoded.png"); const args = [ "-limit", "memory", @@ -51,13 +53,13 @@ async function rawToTiff( "-depth", "8", "-strip", - "-compress", - "Zip", + "-define", + "png:compression-level=1", ]; if (maxDimension) { args.push("-resize", `${maxDimension}x${maxDimension}>`); } - args.push(`tiff:${output}`); + args.push(`png:${output}`); try { await execFileAsync("convert", args, { @@ -118,7 +120,7 @@ export async function renderPhotoJpeg(input: { let cleanup: (() => Promise) | undefined; if (input.kind === "raw") { - const decoded = await rawToTiff(input.filePath, input.maxDimension); + const decoded = await rawToPng(input.filePath, input.maxDimension); decodedPath = decoded.path; cleanup = decoded.cleanup; }