diff --git a/src/http/avatar.ts b/src/http/avatar.ts index 878acaf..f302c56 100644 --- a/src/http/avatar.ts +++ b/src/http/avatar.ts @@ -29,14 +29,24 @@ async function generateAvatar(res: Response, options: AvatarOptions) { return res.status(404).json({ message: 'Body sprite file not found' }) } - let avatar = sharp(bodySpritePath) + let avatar = sharp(bodySpritePath).extend({ + top: 2, + bottom: 2, + background: { r: 0, g: 0, b: 0, alpha: 0 } + }) if (options.characterHairId) { const characterHair = await CharacterHairRepository.getById(options.characterHairId) if (characterHair?.spriteId) { const hairSpritePath = getPublicPath('sprites', characterHair.spriteId, 'front.png') if (fs.existsSync(hairSpritePath)) { - avatar = avatar.composite([{ input: hairSpritePath, gravity: 'north' }]) + avatar = avatar.composite([{ + input: hairSpritePath, + gravity: 'north', + // Top is originY in min + // top: Math.round(Number(characterHair.sprite!.spriteActions.find((action) => action.action === 'front')?.originY ?? 0)), + // left: 0 + }]) } else { console.error(`Hair sprite file not found: ${hairSpritePath}`) } diff --git a/src/repositories/characterHairRepository.ts b/src/repositories/characterHairRepository.ts index 1790f43..e030cf6 100644 --- a/src/repositories/characterHairRepository.ts +++ b/src/repositories/characterHairRepository.ts @@ -12,9 +12,16 @@ class CharacterHairRepository { } }) } - async getById(id: number): Promise { + async getById(id: number) { return prisma.characterHair.findUnique({ - where: { id } + where: { id }, + include: { + sprite: { + include: { + spriteActions: true + } + } + } }) } }