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:
@@ -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);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user