From 2ee3efd6b8be3a8d31b9d426bf0fe7b04e4a67a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Gr=C3=A4ber?= Date: Fri, 3 Nov 2023 17:44:31 +0100 Subject: [PATCH] [Fix] Add an additional/alternative auto-image-rotate option - On our system, for a so far unknown reason, the exif data is somehow in cases of 6 and 8 not correctly processed with the core "auto_orient" checkbox option - This commit intoduces a seperate, additional handling, which basically "inverts" the image-orientation in exif data cases 6 and 8. - Background info: it should work like this: https://jdhao.github.io/2019/07/31/image_rotation_exif_info/ (and thats also how it is handled so far) but -> - that seems somehow not always reliable, see also this study here: https://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/ - And therefore, this "workaround"-option introduced hereby --- Classes/Service/ImageResizer.php | 36 +++++++++++++++++++++++++++- Configuration/TCA/Module/Options.php | 8 ++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/Classes/Service/ImageResizer.php b/Classes/Service/ImageResizer.php index 037edde1..fdad6f80 100644 --- a/Classes/Service/ImageResizer.php +++ b/Classes/Service/ImageResizer.php @@ -310,7 +310,41 @@ public function processFile( if ((bool)$ruleset['auto_orient'] === true) { $orientation = ImageUtility::getOrientation($fileName); $isRotated = ImageUtility::isRotated($orientation); - $gifCreator->scalecmd = '-auto-orient ' . $gifCreator->scalecmd; + + if ((bool)$ruleset['auto_orient_custom'] === true) { + switch ((int) $orientation) { + + case 2: + $gifCreator->scalecmd = '-flop'; + break; + + case 3: + $gifCreator->scalecmd = '-rotate 180'; + break; + + case 4: + $gifCreator->scalecmd = '-rotate 180 -flop'; + break; + + case 5: + $gifCreator->scalecmd = '-rotate -90 -flop'; + break; + + case 6: + $gifCreator->scalecmd = '-rotate -90'; + break; + + case 7: + $gifCreator->scalecmd = '-rotate 90 -flop'; + break; + + case 8: + $gifCreator->scalecmd = '-rotate 90'; + break; + } + } else { + $gifCreator->scalecmd = '-auto-orient ' . $gifCreator->scalecmd; + } } if ( diff --git a/Configuration/TCA/Module/Options.php b/Configuration/TCA/Module/Options.php index 77195645..842d1d4c 100644 --- a/Configuration/TCA/Module/Options.php +++ b/Configuration/TCA/Module/Options.php @@ -85,6 +85,12 @@ 'type' => 'check', ], ], + 'auto_orient_custom' => [ + 'label' => 'Use custom auto_orient (flop rotate 6 and 8 handling, based on image exif)', + 'config' => [ + 'type' => 'check', + ], + ], 'keep_metadata' => [ 'label' => 'LLL:EXT:image_autoresize/Resources/Private/Language/locallang_tca.xlf:tx_imageautoresize.keep_metadata', 'config' => [ @@ -121,7 +127,7 @@ 'directories,threshold,file_types, --palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:ALT.imgDimensions;dimensions, --div--;LLL:EXT:image_autoresize/Resources/Private/Language/locallang_tca.xlf:tabs.options, - auto_orient,keep_metadata,resize_png_with_alpha,conversion_mapping, + auto_orient,auto_orient_custom,keep_metadata,resize_png_with_alpha,conversion_mapping, --div--;LLL:EXT:image_autoresize/Resources/Private/Language/locallang_tca.xlf:tabs.rulesets, rulesets '],