1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 02:39:33 +02:00

Generate 600x600 and 1500x1500 avatars

This commit is contained in:
Chocobozzz 2024-02-26 14:33:22 +01:00
parent fb2dc40858
commit 109e93c139
No known key found for this signature in database
GPG key ID: 583A612D890159BE
19 changed files with 83 additions and 33 deletions

View file

@ -31,7 +31,7 @@ export async function processImage (options: {
if (extension === '.gif') {
await processGIF({ path, destination, newSize })
} else {
await jimpProcessor(path, destination, newSize, extension)
await jimpProcessor({ path, destination, newSize, inputExt: extension })
}
if (keepOriginal !== true) await remove(path)
@ -56,7 +56,17 @@ export async function getImageSize (path: string) {
// Private
// ---------------------------------------------------------------------------
async function jimpProcessor (path: string, destination: string, newSize: { width: number, height: number }, inputExt: string) {
async function jimpProcessor (options: {
path: string
destination: string
newSize: {
width: number
height: number
}
inputExt: string
}) {
const { path, destination, newSize, inputExt } = options
let sourceImage: Jimp
const inputBuffer = await readFile(path)
@ -125,7 +135,7 @@ function skipProcessing (options: {
const { width, height } = newSize
if (hasExif(sourceImage)) return false
if (sourceImage.getWidth() > width || sourceImage.getHeight() > height) return false
if (sourceImage.getWidth() !== width || sourceImage.getHeight() !== height) return false
if (inputExt !== outputExt) return false
const kB = 1000