Don't resize remote actor images
Use their own size. In the future we may imagine resizing remote images on demand like classic CDNs
This commit is contained in:
parent
baefe61cff
commit
565a11d8d3
5 changed files with 22 additions and 16 deletions
|
@ -25,13 +25,15 @@ export class FFmpegImage {
|
|||
processGIF (options: {
|
||||
path: string
|
||||
destination: string
|
||||
newSize: { width: number, height: number }
|
||||
newSize?: { width: number, height: number }
|
||||
}): Promise<void> {
|
||||
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()
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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<MActorI
|
|||
}
|
||||
}
|
||||
|
||||
return ACTOR_IMAGES_SIZE[image.type][0]
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
|
|
@ -118,7 +118,7 @@ export abstract class AbstractPermanentFileCache <M extends ImageModel> {
|
|||
private downloadImage (options: {
|
||||
fileUrl: string
|
||||
filename: string
|
||||
size: { width: number, height: number }
|
||||
size?: { width: number, height: number }
|
||||
}) {
|
||||
const downloaderOptions = {
|
||||
url: options.fileUrl,
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue