This commit is contained in:
seb
2026-10-19 02:03:44 +02:00
parent e14a8ee8f0
commit 1bf99deeb9
2 changed files with 19 additions and 7 deletions

View File

@@ -11,13 +11,19 @@ const log = createLogger('import');
// #region SkeleHash Computation
/**
* Computes SkeleHash base62 hash for an image buffer.
* Computes SkeleHash base62 hash for an image buffer or base64 string.
*
* @param {Buffer} buffer
* @param {Buffer|string} buffer
* @returns {Promise<{base62: string, width: number, height: number, hashLength: number}|null>}
*/
export async function computeSkeleHash(buffer) {
const { data, info } = await sharp(buffer)
if (!buffer) return null;
let input = buffer;
if (typeof input === 'string') {
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()