Issue Bug Resolved

#110579minWidth without explicit width scales image DOWN to minWidth instead of only upscaling small images

John Petsis 09/01/26, 08:51 updated 09/10/26, 08:15

Description

Description

Calling f:uri.image (or any image processing) with @minWidth@ but WITHOUT an explicit width*
scales the image *down to minWidth pixels
whenever the source image is narrower than maxWidth.
The minWidth option is supposed to only guarantee a minimum size (upscaling small sources),
never to shrink a large image.

Steps to reproduce

Minimal Fluid:


<f:uri.image image="{file}" minWidth="30" maxWidth="1500" />

with a source image wider than 30 px but narrower than 1500 px, e.g. 1380×720
(a common case, images smaller than the requested cap).

Result:

a processed file of 30×16 px is generated and returned.

Expected:

the source dimensions (1380×720), since neither minWidth (upscale small images only)
nor maxWidth (shrink only images wider than 1500) applies.

With a source wider than maxWidth (e.g. 2000 px) the same call works correctly and returns
1500×… which is why this bug only surfaces for image sets that contain smaller sources.

Root cause

TYPO3\CMS\Core\Imaging\ImageProcessingInstructions::fromCropScaleValues()
(typo3/sysext/core/Classes/Imaging/ImageProcessingInstructions.php):

if (!empty($options['minWidth'])) {
    if ($width < $options['minWidth'] || ($width === 0 && $cropArea->getWidth() < $options['minWidth'])) {
        $width = (int)$options['minWidth'];
        $height = max(1, (int)round($cropArea->getHeight() * ($width / $cropArea->getWidth())));
    }
}

When no explicit width is requested, $width is 0 (= auto). The first clause
@$width < $options[‘minWidth’]@ evaluates 0 < 30 → always true, so the image is scaled to
@minWidth@ . The second clause $width === 0 && $cropArea->getWidth() < $options['minWidth']
is the intended guard for the auto-width case, but it is short-circuited by the first condition.

Note the asymmetry with the maxWidth clause, which handles the auto case correctly:
@$width > $options[‘maxWidth’] || ($width === 0 && $cropArea->getWidth() > $options[‘maxWidth’])@
there the 0 > maxWidth branch is harmless. For minWidth it is not.

Trace for 1380×720, minWidth: 30, maxWidth: 1500 :
1. maxWidth clause: width(0) === 0 && cropArea.getWidth() 1380 > 1500 → false → no clamp, width stays 0.
2. minWidth clause: width(0) < 30 → true → width = 30 , height = round(720 × 30/1380) = 16 → 30×16.

Same trace with source 2000×1072: step 1 clamps to 1500, step 2 is skipped (1500 < 30 = false) →
correct 1500px output.

Suggested fix

Guard the auto-width case with the source-width check (also applies to the minHeight clause):

if (!empty($options['minWidth'])) {
    if ($width > 0 && $width < $options['minWidth']) {
        $width = (int)$options['minWidth'];
        $height = max(1, (int)round($cropArea->getHeight() * ($width / $cropArea->getWidth())));
    } elseif ($width === 0 && $cropArea->getWidth() < $options['minWidth']) {
        $width = (int)$options['minWidth'];
        $height = max(1, (int)round($cropArea->getHeight() * ($width / $cropArea->getWidth())));
    }
}

The minHeight clause has the same flaw and needs the equivalent fix.

Affected version 13.4.30 still present on Main branch .

Reviews 3

History 25

  1. Maike Kiebele commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2026-09-10T08:15:11+00:00" > 09/10/26, 08:15 </span>

    Applied in changeset commit:bcfe56994674f1e91fe5b1657dc64cd6586f043b.