summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/ImageProcessingService.ts
diff options
context:
space:
mode:
authortamaina <tamaina@hotmail.co.jp>2022-12-30 12:00:50 +0900
committerGitHub <noreply@github.com>2022-12-30 12:00:50 +0900
commit8b46edeccf5a8907afbb871e3eb5b3b8eef967a8 (patch)
tree1411e540282c4b0d2365d3a2c7e01902a3403a3a /packages/backend/src/core/ImageProcessingService.ts
parentfix(client): fix position calculation of nested context menu (diff)
downloadsharkey-8b46edeccf5a8907afbb871e3eb5b3b8eef967a8.tar.gz
sharkey-8b46edeccf5a8907afbb871e3eb5b3b8eef967a8.tar.bz2
sharkey-8b46edeccf5a8907afbb871e3eb5b3b8eef967a8.zip
enhance: Proxy custom emojis to reduce image size and accelerate the frontend (#9431)
* 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
Diffstat (limited to 'packages/backend/src/core/ImageProcessingService.ts')
-rw-r--r--packages/backend/src/core/ImageProcessingService.ts20
1 files changed, 14 insertions, 6 deletions
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<IImage> {
- return this.convertSharpToWebp(await sharp(path), width, height, quality);
+ public async convertToWebp(path: string, width: number, height: number, options: sharp.WebpOptions = webpDefault): Promise<IImage> {
+ return this.convertSharpToWebp(await sharp(path), width, height, options);
}
@bindThis
- public async convertSharpToWebp(sharp: sharp.Sharp, width: number, height: number, quality = 85): Promise<IImage> {
+ public async convertSharpToWebp(sharp: sharp.Sharp, width: number, height: number, options: sharp.WebpOptions = webpDefault): Promise<IImage> {
const data = await sharp
.resize(width, height, {
fit: 'inside',
withoutEnlargement: true,
})
.rotate()
- .webp({
- quality,
- })
+ .webp(options)
.toBuffer();
return {