sharp by wasm
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// MARK: - Imports
|
||||
// #region Imports
|
||||
import sharp from 'sharp';
|
||||
import { optimizeImage } from 'wasm-image-optimization';
|
||||
import { encodeRGBA } from 'skelehash-wasm';
|
||||
import { createLogger } from '../../util/logger.js';
|
||||
// #endregion
|
||||
@@ -23,21 +23,22 @@ export async function computeSkeleHash(buffer) {
|
||||
const base64Data = input.includes(',') ? input.split(',')[1] : input;
|
||||
input = Buffer.from(base64Data, 'base64');
|
||||
}
|
||||
const { data, info } = await sharp(input)
|
||||
.rotate()
|
||||
.resize({ width: 200, height: 200, fit: 'inside' })
|
||||
.ensureAlpha()
|
||||
.raw()
|
||||
.toBuffer({ resolveWithObject: true });
|
||||
const raw = await optimizeImage({
|
||||
image: input,
|
||||
width: 200,
|
||||
height: 200,
|
||||
fit: 'contain',
|
||||
format: 'raw',
|
||||
});
|
||||
|
||||
const result = await encodeRGBA(info.width, info.height, data);
|
||||
const result = await encodeRGBA(raw.width, raw.height, raw.data);
|
||||
if (!result?.base62) {
|
||||
throw new Error('encodeRGBA failed to produce a base62 skelehash');
|
||||
}
|
||||
return {
|
||||
base62: result.base62,
|
||||
width: info.width,
|
||||
height: info.height,
|
||||
width: raw.width,
|
||||
height: raw.height,
|
||||
hashLength: result.hash?.length ?? 0,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user