From 1021b7cc8a8a1fae15a3824a1026acdf7466de8f Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 17 Jan 2025 17:37:27 +0100 Subject: [PATCH] Fix copying of JPEG EXIF into WebP --- ts/WoltLabSuite/Core/Image/WebP.ts | 5 +++++ wcfsetup/install/files/js/WoltLabSuite/Core/Image/WebP.js | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/ts/WoltLabSuite/Core/Image/WebP.ts b/ts/WoltLabSuite/Core/Image/WebP.ts index 46ede94a4c..6f23f8476b 100644 --- a/ts/WoltLabSuite/Core/Image/WebP.ts +++ b/ts/WoltLabSuite/Core/Image/WebP.ts @@ -93,6 +93,11 @@ class WebP { } exportWithExif(exif: Exif): Uint8Array { + // The EXIF might originate from a JPEG thus we need to strip the header. + if (exif[0] === 0xff && exif[1] === 0xe1 && exif[2] === 0xc3 && exif[3] === 0xef) { + exif = exif.slice(10); + } + const iccp = this.#getChunk(ChunkHeader.ICCP); const anim = this.#getChunk(ChunkHeader.ANIM); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Image/WebP.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Image/WebP.js index 90af55147d..7d389c95f5 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Image/WebP.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Image/WebP.js @@ -60,6 +60,10 @@ define(["require", "exports"], function (require, exports) { return undefined; } exportWithExif(exif) { + // The EXIF might originate from a JPEG thus we need to strip the header. + if (exif[0] === 0xff && exif[1] === 0xe1 && exif[2] === 0xc3 && exif[3] === 0xef) { + exif = exif.slice(10); + } const iccp = this.#getChunk("ICCP" /* ChunkHeader.ICCP */); const anim = this.#getChunk("ANIM" /* ChunkHeader.ANIM */); const imageData = [];