mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
fix: handle HEIC images in blur-faces and red-eye-removal, show warning when no faces detected
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { readFile, 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 BlurFacesOptions {
|
||||
@@ -39,7 +40,8 @@ export async function blurFaces(
|
||||
const inputPath = join(outputDir, "input_faces.png");
|
||||
const outputPath = join(outputDir, "output_faces.png");
|
||||
|
||||
await writeFile(inputPath, inputBuffer);
|
||||
const pngBuffer = await sharp(inputBuffer).png().toBuffer();
|
||||
await writeFile(inputPath, pngBuffer);
|
||||
const { stdout } = await runPythonWithProgress(
|
||||
"detect_faces.py",
|
||||
[inputPath, outputPath, JSON.stringify(options)],
|
||||
@@ -67,7 +69,8 @@ export async function detectFaces(
|
||||
const inputPath = join(tmpdir(), `detect_faces_${Date.now()}.png`);
|
||||
|
||||
try {
|
||||
await writeFile(inputPath, inputBuffer);
|
||||
const pngBuffer = await sharp(inputBuffer).png().toBuffer();
|
||||
await writeFile(inputPath, pngBuffer);
|
||||
const { stdout } = await runPythonWithProgress(
|
||||
"detect_faces.py",
|
||||
[inputPath, "unused", JSON.stringify({ ...options, detectOnly: true })],
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { readFile, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import sharp from "sharp";
|
||||
import { type ProgressCallback, parseStdoutJson, runPythonWithProgress } from "./bridge.js";
|
||||
|
||||
export interface RedEyeRemovalOptions {
|
||||
@@ -27,7 +28,8 @@ export async function removeRedEye(
|
||||
const inputPath = join(outputDir, "input_redeye.png");
|
||||
const outputPath = join(outputDir, "output_redeye.png");
|
||||
|
||||
await writeFile(inputPath, inputBuffer);
|
||||
const pngBuffer = await sharp(inputBuffer).png().toBuffer();
|
||||
await writeFile(inputPath, pngBuffer);
|
||||
const { stdout } = await runPythonWithProgress(
|
||||
"red_eye_removal.py",
|
||||
[inputPath, outputPath, JSON.stringify(options)],
|
||||
|
||||
Reference in New Issue
Block a user