feat: add sharp-backed image rendering

This commit is contained in:
2026-09-08 17:49:39 -04:00
parent 1f5db91a6a
commit d964b4f0ac
2 changed files with 35 additions and 0 deletions
@@ -2,6 +2,7 @@ import assert from 'node:assert/strict';
import test from 'node:test';
import { createImageDerivativeProcessor } from '../../src/infrastructure/images/image-derivative-processor.js';
import { createSharpImageRenderer } from '../../src/infrastructure/images/sharp-image-renderer.js';
test('renders and stores thumbnail, medium, and large derivatives in order', async () => {
const renderedWidths = [];
@@ -36,4 +37,17 @@ test('requires a renderer implementation', () => {
() => createImageDerivativeProcessor({ imageStorage: {} }),
/renderer is required/,
);
});
test('creates a sharp-backed WebP renderer that resizes to the requested maximum width', async () => {
const renderer = createSharpImageRenderer();
const data = Buffer.from(
'<svg xmlns="http://www.w3.org/2000/svg" width="1024" height="1024" viewBox="0 0 1024 1024"><rect width="1024" height="1024" fill="#ff0000"/></svg>',
);
const output = await renderer({ data, maxWidth: 320 });
assert.ok(output instanceof Buffer);
assert.ok(output.length > 0);
assert.equal(output.subarray(0, 4).toString('ascii'), 'RIFF');
assert.equal(output.subarray(8, 12).toString('ascii'), 'WEBP');
});