move image converting to child_process

This commit is contained in:
rubikscraft
2022-05-01 23:29:56 +02:00
parent 342e52601e
commit 377e6d7709
27 changed files with 1201 additions and 416 deletions

View File

@@ -35,26 +35,23 @@ export class ImageProcessorService {
sharpImage = sharpImage.toColorspace('srgb');
const metadata = await sharpImage.metadata();
const pixels = await sharpImage.raw().toBuffer();
const processedImage = await sharpImage.raw().toBuffer({
resolveWithObject: true,
});
if (
metadata.hasAlpha === undefined ||
metadata.width === undefined ||
metadata.height === undefined
)
return Fail('Invalid image');
if (metadata.width >= 32768 || metadata.height >= 32768) {
processedImage.info.width >= 32768 ||
processedImage.info.height >= 32768
) {
return Fail('Image too large');
}
// Png can be more efficient than QOI, but its just sooooooo slow
const qoiImage = QOIencode(pixels, {
channels: metadata.hasAlpha ? 4 : 3,
const qoiImage = QOIencode(processedImage.data, {
channels: processedImage.info.channels,
colorspace: QOIColorSpace.SRGB,
height: metadata.height,
width: metadata.width,
height: processedImage.info.height,
width: processedImage.info.width,
});
return {