Don't resize remote actor images

Use their own size. In the future we may imagine resizing remote images
on demand like classic CDNs
pull/6610/head
Chocobozzz 2024-09-12 08:46:08 +02:00
parent baefe61cff
commit 565a11d8d3
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
5 changed files with 22 additions and 16 deletions

View File

@ -25,13 +25,15 @@ export class FFmpegImage {
processGIF (options: { processGIF (options: {
path: string path: string
destination: string destination: string
newSize: { width: number, height: number } newSize?: { width: number, height: number }
}): Promise<void> { }): Promise<void> {
const { path, destination, newSize } = options const { path, destination, newSize } = options
this.commandWrapper.buildCommand(path) const command = this.commandWrapper.buildCommand(path)
.size(`${newSize.width}x${newSize.height}`)
.output(destination) if (newSize) command.size(`${newSize.width}x${newSize.height}`)
command.output(destination)
return this.commandWrapper.runCommand() return this.commandWrapper.runCommand()
} }

View File

@ -14,7 +14,7 @@ export function generateImageFilename (extension = '.jpg') {
export async function processImage (options: { export async function processImage (options: {
path: string path: string
destination: string destination: string
newSize: { width: number, height: number } newSize?: { width: number, height: number }
keepOriginal?: boolean // default false keepOriginal?: boolean // default false
}) { }) {
const { path, destination, newSize, keepOriginal = false } = options const { path, destination, newSize, keepOriginal = false } = options
@ -59,7 +59,7 @@ export async function getImageSize (path: string) {
async function jimpProcessor (options: { async function jimpProcessor (options: {
path: string path: string
destination: string destination: string
newSize: { newSize?: {
width: number width: number
height: number height: number
} }
@ -92,7 +92,11 @@ async function jimpProcessor (options: {
return copy(path, destination) 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: { async function autoResize (options: {
@ -126,22 +130,23 @@ function write (image: Jimp, destination: string) {
function skipProcessing (options: { function skipProcessing (options: {
sourceImage: Jimp sourceImage: Jimp
newSize: { width: number, height: number } newSize?: { width: number, height: number }
imageBytes: number imageBytes: number
inputExt: string inputExt: string
outputExt: string outputExt: string
}) { }) {
const { sourceImage, newSize, imageBytes, inputExt, outputExt } = options const { sourceImage, newSize, imageBytes, inputExt, outputExt } = options
const { width, height } = newSize
if (hasExif(sourceImage)) return false 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 if (inputExt !== outputExt) return false
const kB = 1000 const kB = 1000
if (height >= 1000) return imageBytes <= 200 * kB if (newSize) {
if (height >= 500) return imageBytes <= 100 * kB if (newSize.height >= 1000) return imageBytes <= 200 * kB
if (newSize.height >= 500) return imageBytes <= 100 * kB
}
return imageBytes <= 15 * kB return imageBytes <= 15 * kB
} }

View File

@ -1,5 +1,4 @@
import { CONFIG } from '@server/initializers/config.js' 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 { ActorImageModel } from '@server/models/actor/actor-image.js'
import { MActorImage } from '@server/types/models/index.js' import { MActorImage } from '@server/types/models/index.js'
import { AbstractPermanentFileCache } from './shared/index.js' import { AbstractPermanentFileCache } from './shared/index.js'
@ -22,6 +21,6 @@ export class AvatarPermanentFileCache extends AbstractPermanentFileCache<MActorI
} }
} }
return ACTOR_IMAGES_SIZE[image.type][0] return undefined
} }
} }

View File

@ -118,7 +118,7 @@ export abstract class AbstractPermanentFileCache <M extends ImageModel> {
private downloadImage (options: { private downloadImage (options: {
fileUrl: string fileUrl: string
filename: string filename: string
size: { width: number, height: number } size?: { width: number, height: number }
}) { }) {
const downloaderOptions = { const downloaderOptions = {
url: options.fileUrl, url: options.fileUrl,

View File

@ -8,7 +8,7 @@ async function downloadImage (options: {
url: string url: string
destDir: string destDir: string
destName: string destName: string
size: { width: number, height: number } size?: { width: number, height: number }
}) { }) {
const { url, destDir, destName, size } = options const { url, destDir, destName, size } = options