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; }