fix: convert input buffer to PNG before passing to face landmarks Python sidecar

AVIF (and other Sharp-native formats) were written as raw bytes to a
.png temp file, causing PIL to fail with "cannot identify image file".
Every other AI module wrapper already converts via sharp().png().toBuffer()
before writing; face-landmarks was the only one that skipped this step.
This commit is contained in:
SnapOtter
2026-05-13 14:18:49 +08:00
parent 0b3f46407a
commit 648c8c12f5
4 changed files with 15 additions and 10 deletions
+3 -1
View File
@@ -1,6 +1,7 @@
import { unlink, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import sharp from "sharp";
import { type ProgressCallback, parseStdoutJson, runPythonWithProgress } from "./bridge.js";
export interface FaceLandmarkPoint {
@@ -33,7 +34,8 @@ export async function detectFaceLandmarks(
const inputPath = join(tmpdir(), `face_landmarks_${Date.now()}.png`);
try {
await writeFile(inputPath, inputBuffer);
const pngBuffer = await sharp(inputBuffer).png().toBuffer();
await writeFile(inputPath, pngBuffer);
const { stdout } = await runPythonWithProgress(
"face_landmarks.py",
[inputPath, "unused", "{}"],