From de7a1e103650c607db620563fabd63cee73a5ecc Mon Sep 17 00:00:00 2001
From: Benni Mack <benni@typo3.org>
Date: Thu, 21 Sep 2023 00:00:13 +0200
Subject: [PATCH] [BUGFIX] Use proper sample option in GraphicalFunctions
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This change fixes a minor regression introduced
in GraphicalFunctions when $this->scalecmd
was used within GifBuilder to show proper images.

Resolves: #101984
Related: #101981
Releases: main, 12.4
Change-Id: Id20cfde7cc9b2cbc8c88d3c6220e5fb2b0efe67a
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/81121
Tested-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
---
 .../sysext/core/Classes/Imaging/GraphicalFunctions.php | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php b/typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
index 2356abdae98a..a2eed617adaf 100644
--- a/typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
+++ b/typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
@@ -161,7 +161,7 @@ class GraphicalFunctions
      *
      * @var string
      */
-    public $scalecmd = '-auto-orient';
+    public $scalecmd = '-auto-orient -geometry';
 
     /**
      * Used by v5_blur() to simulate 10 continuous steps of blurring
@@ -368,9 +368,13 @@ class GraphicalFunctions
             $params .= ' -crop ' . $data['origW'] . 'x' . $data['origH'] . '+' . $offsetX . '+' . $offsetY . '! +repage';
         }
         // start with the default scale command
-        $command = $this->scalecmd;
+
         // check if we should use -sample or -geometry
-        $command .= ' ' . (($options['sample'] ?? false) ? '-sample' : '-geometry');
+        if ($options['sample'] ?? false) {
+            $command = '-auto-orient -sample';
+        } else {
+            $command = $this->scalecmd;
+        }
         $command .= ' ' . $info[0] . 'x' . $info[1] . '! ' . $params . ' ';
         // re-apply colorspace-setting for the resulting image so colors don't appear to dark (sRGB instead of RGB)
         $command .= ' -colorspace ' . $this->colorspace;
-- 
GitLab