From ef7fb10420d711005c9e62708cdb180a4e191446 Mon Sep 17 00:00:00 2001 From: Roel Zeilstra Date: Wed, 19 Nov 2025 15:09:06 +0100 Subject: [PATCH 1/2] Fix edited image being restored to before edit on image upload. --- .../src/Revolution/Sources/modMediaSource.php | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/core/src/Revolution/Sources/modMediaSource.php b/core/src/Revolution/Sources/modMediaSource.php index 4723bea5dc..1f7ed3e0a2 100644 --- a/core/src/Revolution/Sources/modMediaSource.php +++ b/core/src/Revolution/Sources/modMediaSource.php @@ -32,6 +32,7 @@ use xPDO\Cache\xPDOCacheManager; use xPDO\Om\xPDOCriteria; use xPDO\xPDO; +use MODX\Revolution\modPhpThumb; /** * An abstract base class extend to implement loading your League\Flysystem\AbstractAdapter @@ -1182,7 +1183,27 @@ public function uploadObjectsToContainer($container, array $objects = []) } try { - $this->filesystem->write($newPath, file_get_contents($file['tmp_name'])); + $image_extensions = ['jpg', 'jpeg']; + $file_extension = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)); + + if (in_array($file_extension, $image_extensions)) { + $exif = @exif_read_data($file['tmp_name']); + if (!empty($exif['Orientation']) && $exif['Orientation'] > 1) { + $phpThumb = new modPhpThumb($this->xpdo, []); + $phpThumb->setSourceFilename($file['tmp_name']); + $phpThumb->setParameter('ar', 'x'); + if ($phpThumb->GenerateThumbnail()) { + $image_string = $phpThumb->OutputThumbnailData(); + $this->filesystem->write($newPath, $image_string); + } else { + $this->filesystem->write($newPath, file_get_contents($file['tmp_name'])); + } + } else { + $this->filesystem->write($newPath, file_get_contents($file['tmp_name'])); + } + } else { + $this->filesystem->write($newPath, file_get_contents($file['tmp_name'])); + } } catch (FilesystemException | UnableToWriteFile $e) { $this->addError('path', $this->xpdo->lexicon('file_err_upload')); $this->xpdo->log(modX::LOG_LEVEL_ERROR, $e->getMessage()); From b58852957d55df9488b4b6ea1f6e36ac4e5df338 Mon Sep 17 00:00:00 2001 From: Roel Zeilstra Date: Wed, 19 Nov 2025 15:09:40 +0100 Subject: [PATCH 2/2] Add doc line --- core/src/Revolution/Sources/modMediaSource.php | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/Revolution/Sources/modMediaSource.php b/core/src/Revolution/Sources/modMediaSource.php index 1f7ed3e0a2..3a73675f32 100644 --- a/core/src/Revolution/Sources/modMediaSource.php +++ b/core/src/Revolution/Sources/modMediaSource.php @@ -1182,6 +1182,7 @@ public function uploadObjectsToContainer($container, array $objects = []) $this->xpdo->log(modX::LOG_LEVEL_ERROR, $e->getMessage()); } + // Check if Orientation is correct due to EXIF issues in JPG/JPEG and rotate if needed. try { $image_extensions = ['jpg', 'jpeg']; $file_extension = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));