From 272b8f21df2c000b1c6c4579d8579193abb4dbd4 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Mon, 18 Sep 2023 20:00:44 +0900 Subject: [PATCH 1/6] fix(backend): original image is not original image on web page --- packages/backend/src/core/DriveService.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/core/DriveService.ts b/packages/backend/src/core/DriveService.ts index a4f6a96a41da..281607512a7f 100644 --- a/packages/backend/src/core/DriveService.ts +++ b/packages/backend/src/core/DriveService.ts @@ -302,12 +302,14 @@ export class DriveService { const metadata = await img.metadata(); isAnimated = !!(metadata.pages && metadata.pages > 1); + // nirila Extension: We want to keep original size as possible + // noinspection PointlessBooleanExpressionJS satisfyWebpublic = !!( type !== 'image/svg+xml' && // security reason - type !== 'image/avif' && // not supported by Mastodon and MS Edge - !(metadata.exif ?? metadata.iptc ?? metadata.xmp ?? metadata.tifftagPhotoshop) && - metadata.width && metadata.width <= 2048 && - metadata.height && metadata.height <= 2048 + type !== 'image/avif' // not supported by Mastodon and MS Edge + //!(metadata.exif ?? metadata.iptc ?? metadata.xmp ?? metadata.tifftagPhotoshop) && + //metadata.width && metadata.width <= 2048 && + //metadata.height && metadata.height <= 2048 ); } catch (err) { this.registerLogger.warn(`sharp failed: ${err}`); From 7c339558a97b30c6099668952936933d2b1e3e2a Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Mon, 18 Sep 2023 20:17:14 +0900 Subject: [PATCH 2/6] Update packages/backend/src/core/DriveService.ts --- packages/backend/src/core/DriveService.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/core/DriveService.ts b/packages/backend/src/core/DriveService.ts index 281607512a7f..dba2a8a3366a 100644 --- a/packages/backend/src/core/DriveService.ts +++ b/packages/backend/src/core/DriveService.ts @@ -306,8 +306,8 @@ export class DriveService { // noinspection PointlessBooleanExpressionJS satisfyWebpublic = !!( type !== 'image/svg+xml' && // security reason - type !== 'image/avif' // not supported by Mastodon and MS Edge - //!(metadata.exif ?? metadata.iptc ?? metadata.xmp ?? metadata.tifftagPhotoshop) && + type !== 'image/avif' && // not supported by Mastodon and MS Edge + !(metadata.exif ?? metadata.iptc ?? metadata.xmp ?? metadata.tifftagPhotoshop) //metadata.width && metadata.width <= 2048 && //metadata.height && metadata.height <= 2048 ); From 77fdd91843ad662b4feeb52c89b3352480ec3a61 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Mon, 18 Sep 2023 20:34:44 +0900 Subject: [PATCH 3/6] chore(backend): recompress with original size or 8192 pixels --- packages/backend/src/core/DriveService.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/backend/src/core/DriveService.ts b/packages/backend/src/core/DriveService.ts index dba2a8a3366a..a9efeaf3a683 100644 --- a/packages/backend/src/core/DriveService.ts +++ b/packages/backend/src/core/DriveService.ts @@ -296,21 +296,26 @@ export class DriveService { let img: sharp.Sharp | null = null; let satisfyWebpublic: boolean; let isAnimated: boolean; + let compressedWidth: number; + let compressedHeight: number; try { img = await sharpBmp(path, type); const metadata = await img.metadata(); isAnimated = !!(metadata.pages && metadata.pages > 1); + const maxSize = 8192; // nirila Extension: We want to keep original size as possible // noinspection PointlessBooleanExpressionJS satisfyWebpublic = !!( type !== 'image/svg+xml' && // security reason type !== 'image/avif' && // not supported by Mastodon and MS Edge - !(metadata.exif ?? metadata.iptc ?? metadata.xmp ?? metadata.tifftagPhotoshop) - //metadata.width && metadata.width <= 2048 && - //metadata.height && metadata.height <= 2048 + !(metadata.exif ?? metadata.iptc ?? metadata.xmp ?? metadata.tifftagPhotoshop) && + metadata.width && metadata.width <= maxSize && + metadata.height && metadata.height <= maxSize ); + compressedWidth = metadata.width && metadata.width <= maxSize ? metadata.width : maxSize; + compressedHeight = metadata.height && metadata.height <= maxSize ? metadata.height : maxSize; } catch (err) { this.registerLogger.warn(`sharp failed: ${err}`); return { @@ -327,9 +332,9 @@ export class DriveService { try { if (['image/jpeg', 'image/webp', 'image/avif'].includes(type)) { - webpublic = await this.imageProcessingService.convertSharpToWebp(img, 2048, 2048); + webpublic = await this.imageProcessingService.convertSharpToWebp(img, compressedWidth, compressedHeight); } else if (['image/png', 'image/bmp', 'image/svg+xml'].includes(type)) { - webpublic = await this.imageProcessingService.convertSharpToPng(img, 2048, 2048); + webpublic = await this.imageProcessingService.convertSharpToPng(img, compressedWidth, compressedHeight); } else { this.registerLogger.debug('web image not created (not an required image)'); } From fbe7f31ca22521ab9faabf54659fcf12124853af Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Mon, 18 Sep 2023 20:37:11 +0900 Subject: [PATCH 4/6] =?UTF-8?q?docs(changleog):=204K/8K=E7=94=BB=E5=83=8F?= =?UTF-8?q?=E3=81=8C2K=E4=BB=A5=E4=B8=8B=E3=81=AB=E3=81=AA=E3=81=A3?= =?UTF-8?q?=E3=81=A6=E3=81=97=E3=81=BE=E3=81=86=E3=81=AE=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7d6e20aebe1..a30faad295d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ ## 13.14.2-kinel.5 (unreleased) ### General +- 4K/8K画像が2K以下になってしまうのを修正しました ### Client From 7b491445e7f4b2ee214fab20485cc1702b859a25 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Thu, 21 Sep 2023 16:36:56 +0900 Subject: [PATCH 5/6] chore: make maxWebImageSize configurable --- packages/backend/src/config.ts | 1 + packages/backend/src/core/DriveService.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/config.ts b/packages/backend/src/config.ts index 92005a2747a3..3842587f7275 100644 --- a/packages/backend/src/config.ts +++ b/packages/backend/src/config.ts @@ -97,6 +97,7 @@ export type Source = { abuseDiscordHook: string; disableAbuseRepository?: boolean; notificationLimit?: number; + maxWebImageSize?: number; } }; diff --git a/packages/backend/src/core/DriveService.ts b/packages/backend/src/core/DriveService.ts index a9efeaf3a683..35e2ec322a14 100644 --- a/packages/backend/src/core/DriveService.ts +++ b/packages/backend/src/core/DriveService.ts @@ -304,7 +304,7 @@ export class DriveService { const metadata = await img.metadata(); isAnimated = !!(metadata.pages && metadata.pages > 1); - const maxSize = 8192; + const maxSize = this.config.nirila?.maxWebImageSize ?? 8192; // nirila Extension: We want to keep original size as possible // noinspection PointlessBooleanExpressionJS satisfyWebpublic = !!( From 707fce95f2e991f552a27291a287c3f4e01edf10 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Mon, 25 Sep 2023 20:51:50 +0900 Subject: [PATCH 6/6] chore: improve changelog Co-authored-by: Sayamame-beans <61457993+Sayamame-beans@users.noreply.github.com> --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bebdfe554931..a0ac30a9ada9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,8 @@ --- -- 4K/8K画像が2K以下になってしまうのを修正しました +- 4K/8K画像が2K以下で表示されてしまう問題を修正しました + - 既存のファイルは更新されず、新規アップロード分にのみ適用されます ### Client - Fix: ノートのメニューにある「詳細」ボタンの表示がログイン/ログアウト状態で統一されていない問題を修正