sharp by wasm

This commit is contained in:
seb
2026-10-28 01:46:48 +01:00
parent ccb81cdb26
commit 2d4d894881
12 changed files with 198 additions and 767 deletions

View File

@@ -1,35 +1,21 @@
import sharp from 'sharp';
import { optimizeImage } from 'wasm-image-optimization';
/**
* Creates sample PNG image buffer.
*/
async function makeSampleImage(width = 200, height = 200, color = { r: 50, g: 120, b: 220 }) {
return sharp({
create: {
width,
height,
channels: 4,
background: { ...color, alpha: 1 },
},
})
.png()
.toBuffer();
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}"><rect width="${width}" height="${height}" fill="rgb(${color.r},${color.g},${color.b})"/></svg>`;
const res = await optimizeImage({ image: svg, format: 'png' });
return Buffer.from(res.data);
}
/**
* Creates sample AVIF thumbnail buffer.
*/
async function makeSampleThumb(width = 64, height = 64) {
return sharp({
create: {
width,
height,
channels: 4,
background: { r: 200, g: 60, b: 60, alpha: 1 },
},
})
.avif()
.toBuffer();
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}"><rect width="${width}" height="${height}" fill="rgb(200,60,60)"/></svg>`;
const res = await optimizeImage({ image: svg, format: 'avif' });
return Buffer.from(res.data);
}
/**