sharp by wasm
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user