@@ -60,17 +60,19 @@ export async function getImage(url: string) {
|
|||||||
const response = await fetch(ensureJpeg(url))
|
const response = await fetch(ensureJpeg(url))
|
||||||
const arrayBuf = await response.arrayBuffer()
|
const arrayBuf = await response.arrayBuffer()
|
||||||
if (response.status !== 200) return null
|
if (response.status !== 200) return null
|
||||||
return sharp(arrayBuf)
|
return (
|
||||||
.resize({
|
sharp(arrayBuf)
|
||||||
width: MAX_AVATAR_RENDER_PX,
|
.resize({
|
||||||
height: MAX_AVATAR_RENDER_PX,
|
width: MAX_AVATAR_RENDER_PX,
|
||||||
fit: 'inside',
|
height: MAX_AVATAR_RENDER_PX,
|
||||||
withoutEnlargement: true,
|
fit: 'inside',
|
||||||
})
|
withoutEnlargement: true,
|
||||||
// quality 95: this is a second lossy encode over an already-lossy CDN
|
})
|
||||||
// jpeg, and the default (80) visibly softens avatars at card sizes
|
// quality 95: this is a second lossy encode over an already-lossy CDN
|
||||||
.jpeg({quality: 95})
|
// jpeg, and the default (80) visibly softens avatars at card sizes
|
||||||
.toBuffer()
|
.jpeg({quality: 95})
|
||||||
|
.toBuffer()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CDN URLs end with @jpeg, @webp, or no extension (which may default to webp).
|
// CDN URLs end with @jpeg, @webp, or no extension (which may default to webp).
|
||||||
|
|||||||
Reference in New Issue
Block a user