#109964Floating-point precision error in image crop causes ImageMagick command failure (PHP 8.4)
Description
Image processing intermittently fails when cropping is applied. The ImageMagick/GraphicsMagick command receives crop offset values in scientific notation (e.g. 1.1368683772162E-13) which it cannot parse, resulting in an invalid geometry error.
The issue surfaced after upgrading from PHP 8.3 to PHP 8.4 alongside a TYPO3 v12 to v13 upgrade.
Steps to reproduce:
The issue occurs with certain image dimension and crop ratio combinations. It is not consistently reproducible because the outcome depends on whether floating-point arithmetic produces an exact zero or a near-zero residual for a given image.
Root cause:
Area::applyRatioRestriction() in typo3/cms-core/Classes/Imaging/ImageManipulation/Area.php computes offset adjustments like:
$newArea->x += ($this->width - $newArea->width) / 2;
$newArea->y += ($this->height - $newArea->height) / 2;
When the crop area already matches the target ratio, the subtraction should yield 0.0, but floating-point arithmetic can produce near-zero residuals like 1.1368683772162E-13.
In GraphicalFunctions.php line 407, these float values are concatenated directly into the ImageMagick command string:
$command .= ' -crop ' . $cropArea->getWidth() . 'x' . $cropArea->getHeight()
. '+' . $cropArea->getOffsetLeft() . '+' . $cropArea->getOffsetTop() . '! +repage ';
Why PHP 8.4 triggers this:
The floating-point imprecision in applyRatioRestriction() likely existed in earlier PHP versions as well. However, PHP 8.4 changed how float values are converted to strings, more consistently using scientific notation for very small and very large values. On PHP 8.3, a near-zero value like 1.1368683772162E-13 would typically render as 0 in string concatenation context. PHP 8.4 faithfully renders the scientific notation form, which ImageMagick cannot parse.
Since PHP 8.4 is the primary target runtime for TYPO3 v13, this will affect a growing number of installations as they upgrade.
Suggested fix:
The -crop geometry values are pixel coordinates and should be integers. Casting to int via round() eliminates both the precision error and the scientific notation problem:
$command .= ' -crop ' . (int)round($cropArea->getWidth()) . 'x' . (int)round($cropArea->getHeight())
. '+' . (int)round($cropArea->getOffsetLeft()) . '+' . (int)round($cropArea->getOffsetTop()) . '! +repage ';Reviews 3
History 411
-
Gerrit Code Review pushed patch set 1 for main to change 94297 status
NewUnder Review <span data-processor="relativetime" data-value="2026-06-03T11:45:40+00:00" > 06/03/26, 11:45 </span> -
Gerrit Code Review pushed patch set 2 for main to change 94297 <span data-processor="relativetime" data-value="2026-06-03T14:13:21+00:00" > 06/03/26, 14:13 </span>
-
Gerrit Code Review pushed patch set 3 for main to change 94297 <span data-processor="relativetime" data-value="2026-06-03T14:23:15+00:00" > 06/03/26, 14:23 </span>
-
Gerrit Code Review pushed patch set 4 for main to change 94297 <span data-processor="relativetime" data-value="2026-06-03T14:28:33+00:00" > 06/03/26, 14:28 </span>
-
Simon Schaufelberger changed description <span data-processor="relativetime" data-value="2026-06-03T19:19:22+00:00" > 06/03/26, 19:19 </span>
-
Simon Schaufelberger changed description <span data-processor="relativetime" data-value="2026-06-03T19:21:54+00:00" > 06/03/26, 19:21 </span>
-
Gerrit Code Review pushed patch set 5 for main to change 94297 <span data-processor="relativetime" data-value="2026-06-04T19:00:34+00:00" > 06/04/26, 19:00 </span>
-
Gerrit Code Review pushed patch set 1 for 14.3 to change 94449 <span data-processor="relativetime" data-value="2026-06-10T01:53:39+00:00" > 06/10/26, 01:53 </span>
-
Gerrit Code Review pushed patch set 1 for 13.4 to change 94450 <span data-processor="relativetime" data-value="2026-06-10T01:53:54+00:00" > 06/10/26, 01:53 </span>
-
Stig Nørgaard Færch commented and changed status
Under ReviewResolved done0 %100 % <span data-processor="relativetime" data-value="2026-06-10T02:00:11+00:00" > 06/10/26, 02:00 </span> -
Benni Mack changed status
ResolvedClosed <span data-processor="relativetime" data-value="2026-08-11T08:50:51+00:00" > 08/11/26, 08:50 </span>
Applied in changeset commit:2661ddd16ab43966fb96d6044ecfd85d40c72af8.