diff --git a/packages/ffmpeg/src/ffmpeg-images.ts b/packages/ffmpeg/src/ffmpeg-images.ts index 9ecb0bfd8..bd66ad6df 100644 --- a/packages/ffmpeg/src/ffmpeg-images.ts +++ b/packages/ffmpeg/src/ffmpeg-images.ts @@ -25,13 +25,15 @@ export class FFmpegImage { processGIF (options: { path: string destination: string - newSize: { width: number, height: number } + newSize?: { width: number, height: number } }): Promise { const { path, destination, newSize } = options - this.commandWrapper.buildCommand(path) - .size(`${newSize.width}x${newSize.height}`) - .output(destination) + const command = this.commandWrapper.buildCommand(path) + + if (newSize) command.size(`${newSize.width}x${newSize.height}`) + + command.output(destination) return this.commandWrapper.runCommand() } diff --git a/server/core/helpers/image-utils.ts b/server/core/helpers/image-utils.ts index 9a99dffc9..c36aa34de 100644 --- a/server/core/helpers/image-utils.ts +++ b/server/core/helpers/image-utils.ts @@ -14,7 +14,7 @@ export function generateImageFilename (extension = '.jpg') { export async function processImage (options: { path: string destination: string - newSize: { width: number, height: number } + newSize?: { width: number, height: number } keepOriginal?: boolean // default false }) { const { path, destination, newSize, keepOriginal = false } = options @@ -59,7 +59,7 @@ export async function getImageSize (path: string) { async function jimpProcessor (options: { path: string destination: string - newSize: { + newSize?: { width: number height: number } @@ -92,7 +92,11 @@ async function jimpProcessor (options: { return copy(path, destination) } - await autoResize({ sourceImage, newSize, destination }) + if (newSize) { + await autoResize({ sourceImage, newSize, destination }) + } else { + await write(sourceImage, destination) + } } async function autoResize (options: { @@ -126,22 +130,23 @@ function write (image: Jimp, destination: string) { function skipProcessing (options: { sourceImage: Jimp - newSize: { width: number, height: number } + newSize?: { width: number, height: number } imageBytes: number inputExt: string outputExt: string }) { const { sourceImage, newSize, imageBytes, inputExt, outputExt } = options - const { width, height } = newSize if (hasExif(sourceImage)) return false - if (sourceImage.getWidth() !== width || sourceImage.getHeight() !== height) return false + if (newSize && (sourceImage.getWidth() !== newSize.width || sourceImage.getHeight() !== newSize.height)) return false if (inputExt !== outputExt) return false const kB = 1000 - if (height >= 1000) return imageBytes <= 200 * kB - if (height >= 500) return imageBytes <= 100 * kB + if (newSize) { + if (newSize.height >= 1000) return imageBytes <= 200 * kB + if (newSize.height >= 500) return imageBytes <= 100 * kB + } return imageBytes <= 15 * kB } diff --git a/server/core/lib/files-cache/avatar-permanent-file-cache.ts b/server/core/lib/files-cache/avatar-permanent-file-cache.ts index cfeed8d6f..d8a63765e 100644 --- a/server/core/lib/files-cache/avatar-permanent-file-cache.ts +++ b/server/core/lib/files-cache/avatar-permanent-file-cache.ts @@ -1,5 +1,4 @@ import { CONFIG } from '@server/initializers/config.js' -import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants.js' import { ActorImageModel } from '@server/models/actor/actor-image.js' import { MActorImage } from '@server/types/models/index.js' import { AbstractPermanentFileCache } from './shared/index.js' @@ -22,6 +21,6 @@ export class AvatarPermanentFileCache extends AbstractPermanentFileCache { private downloadImage (options: { fileUrl: string filename: string - size: { width: number, height: number } + size?: { width: number, height: number } }) { const downloaderOptions = { url: options.fileUrl, diff --git a/server/core/lib/worker/workers/image-downloader.ts b/server/core/lib/worker/workers/image-downloader.ts index c75acf0cd..acc994ab9 100644 --- a/server/core/lib/worker/workers/image-downloader.ts +++ b/server/core/lib/worker/workers/image-downloader.ts @@ -8,7 +8,7 @@ async function downloadImage (options: { url: string destDir: string destName: string - size: { width: number, height: number } + size?: { width: number, height: number } }) { const { url, destDir, destName, size } = options