mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-16 07:04:25 +00:00
Replace sharp with wasm-vips for image processing
Fixes #696 - Replaced sharp dependency with wasm-vips (WebAssembly build of libvips) - Eliminates native build requirements that caused installation failures - Added vips.ts singleton wrapper for async initialization - Updated image-resize.ts and image-convert.ts to use wasm-vips API - Added unit tests for image processing functionality
This commit is contained in:
parent
09d409cc92
commit
e45fc5f91b
7 changed files with 273 additions and 547 deletions
|
|
@ -1,3 +1,5 @@
|
|||
import { getVips } from "./vips.js";
|
||||
|
||||
/**
|
||||
* Convert image to PNG format for terminal display.
|
||||
* Kitty graphics protocol requires PNG format (f=100).
|
||||
|
|
@ -11,16 +13,23 @@ export async function convertToPng(
|
|||
return { data: base64Data, mimeType };
|
||||
}
|
||||
|
||||
const vips = await getVips();
|
||||
if (!vips) {
|
||||
// wasm-vips not available
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
const sharp = (await import("sharp")).default;
|
||||
const buffer = Buffer.from(base64Data, "base64");
|
||||
const pngBuffer = await sharp(buffer).png().toBuffer();
|
||||
const img = vips.Image.newFromBuffer(buffer);
|
||||
const pngBuffer = img.writeToBuffer(".png");
|
||||
img.delete();
|
||||
return {
|
||||
data: pngBuffer.toString("base64"),
|
||||
data: Buffer.from(pngBuffer).toString("base64"),
|
||||
mimeType: "image/png",
|
||||
};
|
||||
} catch {
|
||||
// Sharp not available or conversion failed
|
||||
// Conversion failed
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue