diff --git a/Build/phpstan/phpstan-baseline.neon b/Build/phpstan/phpstan-baseline.neon
index 1e2f538605af8b92d7da0466aa62427d2d68a128..5269c8c006f606bf045ad09c4eeffb2101c43fe5 100644
--- a/Build/phpstan/phpstan-baseline.neon
+++ b/Build/phpstan/phpstan-baseline.neon
@@ -4555,16 +4555,6 @@ parameters:
 			count: 1
 			path: ../../typo3/sysext/frontend/Classes/Http/RequestHandler.php
 
-		-
-			message: "#^Method TYPO3\\\\CMS\\\\Frontend\\\\Imaging\\\\GifBuilder\\:\\:calculateValue\\(\\) should return int but returns float\\.$#"
-			count: 1
-			path: ../../typo3/sysext/frontend/Classes/Imaging/GifBuilder.php
-
-		-
-			message: "#^Method TYPO3\\\\CMS\\\\Frontend\\\\Imaging\\\\GifBuilder\\:\\:checkTextObj\\(\\) should return array but returns null\\.$#"
-			count: 1
-			path: ../../typo3/sysext/frontend/Classes/Imaging/GifBuilder.php
-
 		-
 			message: "#^Property TYPO3\\\\CMS\\\\Core\\\\Imaging\\\\GraphicalFunctions\\:\\:\\$setup \\(array\\) on left side of \\?\\? is not nullable\\.$#"
 			count: 9
diff --git a/typo3/sysext/frontend/Classes/Imaging/GifBuilder.php b/typo3/sysext/frontend/Classes/Imaging/GifBuilder.php
index fda6269cd2a3c0577f7bf038b89b10271844f9f3..682a0ed484aec6d2d733c0dce259cd42e913890b 100644
--- a/typo3/sysext/frontend/Classes/Imaging/GifBuilder.php
+++ b/typo3/sysext/frontend/Classes/Imaging/GifBuilder.php
@@ -545,7 +545,7 @@ class GifBuilder extends GraphicalFunctions
      * Performs caseshift if any.
      *
      * @param array $conf GIFBUILDER object TypoScript properties
-     * @return array Modified $conf array IF the "text" property is not blank
+     * @return array|null Modified $conf array IF the "text" property is not blank
      * @internal
      */
     public function checkTextObj($conf)
@@ -798,14 +798,14 @@ class GifBuilder extends GraphicalFunctions
             } elseif ($sign === '+') {
                 $calculatedValue += $theVal;
             } elseif ($sign === '/' && $theVal) {
-                $calculatedValue = $calculatedValue / $theVal;
+                $calculatedValue /= $theVal;
             } elseif ($sign === '*') {
-                $calculatedValue = $calculatedValue * $theVal;
+                $calculatedValue *= $theVal;
             } elseif ($sign === '%' && $theVal) {
                 $calculatedValue %= $theVal;
             }
         }
-        return round($calculatedValue);
+        return (int)round($calculatedValue);
     }
 
     /**
diff --git a/typo3/sysext/frontend/Tests/Unit/Imaging/GifBuilderTest.php b/typo3/sysext/frontend/Tests/Unit/Imaging/GifBuilderTest.php
new file mode 100644
index 0000000000000000000000000000000000000000..8e22e88cf33678facf79ff2a2f018b07b361aecd
--- /dev/null
+++ b/typo3/sysext/frontend/Tests/Unit/Imaging/GifBuilderTest.php
@@ -0,0 +1,135 @@
+<?php
+
+declare(strict_types=1);
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+namespace TYPO3\CMS\Frontend\Tests\Unit\Imaging;
+
+use TYPO3\CMS\Frontend\Imaging\GifBuilder;
+use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
+
+/**
+ * @covers \TYPO3\CMS\Frontend\Imaging\GifBuilder
+ */
+class GifBuilderTest extends UnitTestCase
+{
+    protected $resetSingletonInstances = true;
+
+    private GifBuilder $subject;
+
+    protected function setUp(): void
+    {
+        parent::setUp();
+
+        $this->subject = new GifBuilder();
+    }
+
+    /**
+     * @return array<string, array{0: non-empty-string}>
+     */
+    public function singleIntegerDataProvider(): array
+    {
+        return [
+            'positive integer' => ['1'],
+            'negative integer' => ['-1'],
+            'zero' => ['0'],
+        ];
+    }
+
+    /**
+     * @test
+     *
+     * @dataProvider singleIntegerDataProvider
+     */
+    public function calcOffsetWithSingleIntegerReturnsTheGivenIntegerAsString(string $number): void
+    {
+        $result = $this->subject->calcOffset($number);
+
+        self::assertSame($number, $result);
+    }
+
+    /**
+     * @test
+     */
+    public function calcOffsetWithMultipleIntegersReturnsTheGivenIntegerCommaSeparated(): void
+    {
+        $numbers = '1,2,3';
+        $result = $this->subject->calcOffset($numbers);
+
+        self::assertSame($numbers, $result);
+    }
+
+    /**
+     * @test
+     */
+    public function calcOffsetTrimsWhitespaceAroundProvidedNumbers(): void
+    {
+        $result = $this->subject->calcOffset(' 1, 2, 3 ');
+
+        self::assertSame('1,2,3', $result);
+    }
+
+    /**
+     * @return array<string, array{0: non-empty-string, 1: non-empty-string}>
+     */
+    public function roundingDataProvider(): array
+    {
+        return [
+            'rounding down' => ['1.1', '1'],
+            'rounding up' => ['1.9', '2'],
+        ];
+    }
+
+    /**
+     * @test
+     *
+     * @dataProvider roundingDataProvider
+     */
+    public function calcOffsetRoundsNumbersToNearestInteger(string $input, string $expectedResult): void
+    {
+        $result = $this->subject->calcOffset($input);
+
+        self::assertSame($expectedResult, $result);
+    }
+
+    /**
+     * @return array<string, array{0: non-empty-string, 1: non-empty-string}>
+     */
+    public function calculationDataProvider(): array
+    {
+        return [
+            'addition of positive numbers' => ['1+1', '2'],
+            'addition of negative numbers' => ['-1+-1', '-2'],
+            'subtraction' => ['5-2', '3'],
+            'multiplication' => ['2*5', '10'],
+            'division with whole-number result' => ['10/5', '2'],
+            'division with rounding up' => ['19/5', '4'],
+            'division with rounding down' => ['21/5', '4'],
+            'modulo' => ['21%5', '1'],
+        ];
+    }
+
+    /**
+     * @test
+     *
+     * @dataProvider calculationDataProvider
+     */
+    public function calcOffsetDoesTheProvidedCalculation(string $input, string $expectedResult): void
+    {
+        $result = $this->subject->calcOffset($input);
+
+        self::assertSame($expectedResult, $result);
+    }
+}