forked from noxious/server
Stash
This commit is contained in:
@ -65,9 +65,12 @@ export class AvatarController extends BaseController {
|
||||
return this.sendError(res, 'Body sprite file not found', 404)
|
||||
}
|
||||
|
||||
// Get body sprite metadata
|
||||
const bodyMetadata = await sharp(bodySpritePath).metadata()
|
||||
|
||||
let avatar = sharp(bodySpritePath).extend({
|
||||
top: 2,
|
||||
bottom: 2,
|
||||
top: 0,
|
||||
bottom: 0,
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 }
|
||||
})
|
||||
|
||||
@ -76,7 +79,21 @@ export class AvatarController extends BaseController {
|
||||
if (characterHair?.sprite?.id) {
|
||||
const hairSpritePath = Storage.getPublicPath('sprites', characterHair.sprite.id, 'front.png')
|
||||
if (fs.existsSync(hairSpritePath)) {
|
||||
avatar = avatar.composite([{ input: hairSpritePath, gravity: 'north' }])
|
||||
// Resize hair sprite to match body dimensions
|
||||
const resizedHair = await sharp(hairSpritePath)
|
||||
.resize(bodyMetadata.width, bodyMetadata.height, {
|
||||
fit: 'contain',
|
||||
background: { r: 0, g: 0, b: 0, alpha: 0 }
|
||||
})
|
||||
.toBuffer()
|
||||
|
||||
avatar = avatar.composite([
|
||||
{
|
||||
input: resizedHair,
|
||||
left: 0,
|
||||
top: -27 // Apply vertical offset
|
||||
}
|
||||
])
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -84,6 +101,7 @@ export class AvatarController extends BaseController {
|
||||
res.setHeader('Content-Type', 'image/png')
|
||||
return avatar.pipe(res)
|
||||
} catch (error) {
|
||||
console.error('Avatar generation error:', error)
|
||||
return this.sendError(res, 'Error generating avatar', 500)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user