This commit is contained in:
seb
2026-10-11 18:20:35 +02:00
parent 1eb5cb4e59
commit fe7be79b90
12 changed files with 1395 additions and 937 deletions

View File

@@ -0,0 +1,41 @@
// MARK: - Imports
// #region Imports
import sharp from 'sharp';
import { encodeRGBA } from 'skelehash-wasm';
import { createLogger } from '../../util/logger.js';
// #endregion
const log = createLogger('import');
// MARK: - SkeleHash Computation
// #region SkeleHash Computation
/**
* Computes SkeleHash base62 hash for an image buffer.
*
* @param {Buffer} buffer
* @returns {Promise<{base62: string, width: number, height: number, hashLength: number}|null>}
*/
export async function computeSkeleHash(buffer) {
try {
const { data, info } = await sharp(buffer)
.rotate()
.resize({ width: 200, height: 200, fit: 'inside' })
.ensureAlpha()
.raw()
.toBuffer({ resolveWithObject: true });
const result = await encodeRGBA(info.width, info.height, data);
return {
base62: result.base62,
width: info.width,
height: info.height,
hashLength: result.hash?.length ?? 0,
};
} catch (err) {
log.warn('Failed to compute skelehash for image:', err.message);
return null;
}
}
// #endregion