feat: add image converter family (sharp)

Regenerates the sample.png test fixture via sharp itself: the
hand-encoded base64 PNG from the plan had valid magic bytes (enough to
fool file-type's signature check) but was malformed past the header,
which libpng rejected as soon as sharp actually tried to decode it.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-30 09:07:26 +02:00
co-authored by Claude Sonnet 5
parent aeebc47379
commit 5a990106b0
3 changed files with 72 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
import sharp from 'sharp';
import { register } from './registry.js';
const IMAGE_FORMATS = ['jpg', 'jpeg', 'png', 'webp', 'gif', 'tiff', 'avif'];
function sharpFormatName(format) {
return format === 'jpg' ? 'jpeg' : format;
}
export function registerImageConverters() {
for (const sourceFormat of IMAGE_FORMATS) {
for (const targetFormat of IMAGE_FORMATS) {
if (sourceFormat === targetFormat) continue;
register({
family: 'image',
sourceFormat,
targetFormat,
convert: async (inputPath, outputPath) => {
await sharp(inputPath).toFormat(sharpFormatName(targetFormat)).toFile(outputPath);
},
});
}
}
}