From 8b46edeccf5a8907afbb871e3eb5b3b8eef967a8 Mon Sep 17 00:00:00 2001 From: tamaina Date: Fri, 30 Dec 2022 12:00:50 +0900 Subject: enhance: Proxy custom emojis to reduce image size and accelerate the frontend (#9431) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(server): /emoji to accept `@.` host expression * fix(client): use MkEmoji for custom emoji in MkEmojiPicker * change convertToWebp * nanka iroiro * remove * fix * nearLosslessは労多くして益少なしなのでやめる * do not cleanup tmp for development * update sharp.js to 0.31.3 * mixed: true * fix MkAutocomplete of 912791b3ab * clean up * https://github.com/misskey-dev/misskey/pull/9431#discussion_r1059215943 --- packages/backend/src/core/ImageProcessingService.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'packages/backend/src/core/ImageProcessingService.ts') diff --git a/packages/backend/src/core/ImageProcessingService.ts b/packages/backend/src/core/ImageProcessingService.ts index 3a61873044..312189eea4 100644 --- a/packages/backend/src/core/ImageProcessingService.ts +++ b/packages/backend/src/core/ImageProcessingService.ts @@ -8,6 +8,16 @@ export type IImage = { ext: string | null; type: string; }; + +export const webpDefault: sharp.WebpOptions = { + quality: 85, + alphaQuality: 95, + lossless: false, + nearLossless: false, + smartSubsample: true, + mixed: true, +}; + import { bindThis } from '@/decorators.js'; @Injectable() @@ -53,21 +63,19 @@ export class ImageProcessingService { * with resize, remove metadata, resolve orientation, stop animation */ @bindThis - public async convertToWebp(path: string, width: number, height: number, quality = 85): Promise { - return this.convertSharpToWebp(await sharp(path), width, height, quality); + public async convertToWebp(path: string, width: number, height: number, options: sharp.WebpOptions = webpDefault): Promise { + return this.convertSharpToWebp(await sharp(path), width, height, options); } @bindThis - public async convertSharpToWebp(sharp: sharp.Sharp, width: number, height: number, quality = 85): Promise { + public async convertSharpToWebp(sharp: sharp.Sharp, width: number, height: number, options: sharp.WebpOptions = webpDefault): Promise { const data = await sharp .resize(width, height, { fit: 'inside', withoutEnlargement: true, }) .rotate() - .webp({ - quality, - }) + .webp(options) .toBuffer(); return { -- cgit v1.2.3-freya