mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
fix: AVIF sidecar crash, edit-metadata silent no-op, passport batch blank images, color-palette hex overflow, OCR log noise
- Convert all AI bridge inputs to PNG before writing to disk so PIL can read AVIF/WebP/TIFF (7 bridge files; face-detection and OCR already had this pattern) - Add title/author aliases to edit-metadata schema so common field names actually write EXIF tags instead of being silently stripped by Zod - Port extend/pad crop logic from passport-photo single endpoint to the batch pipeline so crop regions extending beyond the image get filled with background color instead of producing all-white output - Clamp quantized color channels to 255 in color-palette to prevent Math.round(255/16)*16=256 from producing invalid hex like #100100100 - Compare OCR fallback warning against expected engine name per tier instead of comparing engine name against tier name (always mismatch)
This commit is contained in:
@@ -20,7 +20,8 @@ export async function removeBackground(
|
||||
const inputPath = join(tmpdir(), `rembg_in_${id}.png`);
|
||||
const outputPath = join(outputDir, `rembg_out_${id}.png`);
|
||||
|
||||
await writeFile(inputPath, inputBuffer);
|
||||
const pngBuffer = await sharp(inputBuffer).png().toBuffer();
|
||||
await writeFile(inputPath, pngBuffer);
|
||||
try {
|
||||
const meta = await sharp(inputBuffer).metadata();
|
||||
const megapixels = ((meta.width ?? 0) * (meta.height ?? 0)) / 1_000_000;
|
||||
|
||||
@@ -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 ColorizeOptions {
|
||||
@@ -23,7 +24,8 @@ export async function colorize(
|
||||
const inputPath = join(outputDir, "input_colorize.png");
|
||||
const outputPath = join(outputDir, "output_colorize.png");
|
||||
|
||||
await writeFile(inputPath, inputBuffer);
|
||||
const pngBuffer = await sharp(inputBuffer).png().toBuffer();
|
||||
await writeFile(inputPath, pngBuffer);
|
||||
const { stdout } = await runPythonWithProgress(
|
||||
"colorize.py",
|
||||
[inputPath, outputPath, JSON.stringify(options)],
|
||||
|
||||
@@ -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 EnhanceFacesOptions {
|
||||
@@ -25,7 +26,8 @@ export async function enhanceFaces(
|
||||
const inputPath = join(outputDir, "input_enhance_faces.png");
|
||||
const outputPath = join(outputDir, "output_enhance_faces.png");
|
||||
|
||||
await writeFile(inputPath, inputBuffer);
|
||||
const pngBuffer = await sharp(inputBuffer).png().toBuffer();
|
||||
await writeFile(inputPath, pngBuffer);
|
||||
const { stdout } = await runPythonWithProgress(
|
||||
"enhance_faces.py",
|
||||
[inputPath, outputPath, JSON.stringify(options)],
|
||||
|
||||
@@ -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 async function inpaint(
|
||||
@@ -12,8 +13,10 @@ export async function inpaint(
|
||||
const maskPath = join(outputDir, "mask_inpaint.png");
|
||||
const outputPath = join(outputDir, "output_inpaint.png");
|
||||
|
||||
await writeFile(inputPath, inputBuffer);
|
||||
await writeFile(maskPath, maskBuffer);
|
||||
const pngInput = await sharp(inputBuffer).png().toBuffer();
|
||||
const pngMask = await sharp(maskBuffer).png().toBuffer();
|
||||
await writeFile(inputPath, pngInput);
|
||||
await writeFile(maskPath, pngMask);
|
||||
|
||||
const { stdout } = await runPythonWithProgress("inpaint.py", [inputPath, maskPath, outputPath], {
|
||||
onProgress,
|
||||
|
||||
@@ -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 NoiseRemovalOptions {
|
||||
@@ -28,7 +29,8 @@ export async function noiseRemoval(
|
||||
const inputPath = join(outputDir, "input_denoise.png");
|
||||
const outputPath = join(outputDir, "output_denoise.png");
|
||||
|
||||
await writeFile(inputPath, inputBuffer);
|
||||
const pngBuffer = await sharp(inputBuffer).png().toBuffer();
|
||||
await writeFile(inputPath, pngBuffer);
|
||||
const { stdout } = await runPythonWithProgress(
|
||||
"noise_removal.py",
|
||||
[inputPath, outputPath, JSON.stringify(options)],
|
||||
|
||||
@@ -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 RestorePhotoOptions {
|
||||
@@ -32,7 +33,8 @@ export async function restorePhoto(
|
||||
const inputPath = join(outputDir, "input_restore.png");
|
||||
const outputPath = join(outputDir, "output_restore.png");
|
||||
|
||||
await writeFile(inputPath, inputBuffer);
|
||||
const pngBuffer = await sharp(inputBuffer).png().toBuffer();
|
||||
await writeFile(inputPath, pngBuffer);
|
||||
const { stdout } = await runPythonWithProgress(
|
||||
"restore.py",
|
||||
[inputPath, outputPath, JSON.stringify(options)],
|
||||
|
||||
@@ -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 UpscaleOptions {
|
||||
@@ -28,7 +29,8 @@ export async function upscale(
|
||||
const inputPath = join(outputDir, "input_upscale.png");
|
||||
const outputPath = join(outputDir, "output_upscale.png");
|
||||
|
||||
await writeFile(inputPath, inputBuffer);
|
||||
const pngBuffer = await sharp(inputBuffer).png().toBuffer();
|
||||
await writeFile(inputPath, pngBuffer);
|
||||
const { stdout } = await runPythonWithProgress(
|
||||
"upscale.py",
|
||||
[inputPath, outputPath, JSON.stringify(options)],
|
||||
|
||||
Reference in New Issue
Block a user