Review main Merged

89929[BUGFIX] Handle preview image sizes as max values

Nicole Hummel CR +2 V +2 Easy +3 −3 updated 07/02/25, 11:39

Commit message

The given sizes of a preview image needs to be treated as a maximum
value to allow correct aspect ratio calculation. This is already covered
within the TYPO3\CMS\Core\Imaging\ImageProcessingInstructions but needs
to be adjusted within the actual LocalPreviewHelper as well.

Review

  • Code review CR +2 Done
    • Garvin Hicking +2
    • Benjamin Franzke +1
  • Verified V +2 Done
    • Garvin Hicking +2
    • Benjamin Franzke +1
    • core-ci +1 CI

Issues 3

Files 2

Review log 1418

  1. Nicole Hummel uploaded patch set 1 06/26/25, 22:06

  2. core-ci voted on patch set 1 V -1 06/26/25, 22:16 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/81039

  3. Nicole Hummel uploaded patch set 2 V -1 06/26/25, 22:31

  4. core-ci voted on patch set 2 V +1 06/26/25, 22:38 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/81040

  5. Garvin Hicking commented on patch set 2 CR +1 V +1 06/30/25, 13:15

    Thanks for this :-)
  6. Jasmina Ließmann voted on patch set 2 CR +1 V +1 07/01/25, 12:24

  7. Benjamin Franzke commented on patch set 2 07/01/25, 13:17

    My gut feeling is that this should instead be handled in typo3/sysext/backend/Classes/Form/Element/FileInfoElement.php by passing `150m` instead of `150`, e. g.: ``` $file->process(ProcessedFile::CONTEXT_IMAGEPREVIEW, ['width' => '150m', 'height' => '150m']) ``` *But that does not work* :( The m-suffixes are lost (somewhere) due to normalizations/the deferred rendering (I guess some int-casting).. While searching for that I also found https://github.com/TYPO3/typo3/blob/51ff0e8249dc7a219d505357925fb5c27ba846d4/typo3/sysext/core/Classes/Imaging/ImageProcessingInstructions.php#L369-L378 which pretty much looks like a previous fix/attempt for this issue. That means: It seems we have too many places that try to apply clever max-handling to preview-images.. Feels like we should remove all hacks (including this one) in order to be able to supply the correct value – 150m – in `FileInfoElement`.
  8. Garvin Hicking rebased onto patch set 3 CR +1 V +1 07/01/25, 19:41

  9. Garvin Hicking commented on patch set 3 07/01/25, 19:46

    Reply

    I think your gut feeling is gut. ;) The normalization occurs in `TYPO3\CMS\Core\Resource\Processing\ImagePreviewTask->sanitizeConfiguration()` and applies int casting to the input. I've played around with it a bit and pushed something to https://review.typo3.org/c/Packages/TYPO3.CMS/+/89968 - this does not work properly yet. I tried to not use the magic 'm/c' suffixes but hoped that setting maxWidth/maxHeight instead could be an option. Allowing these suffixes in `sanitizeConfiguration` sadly didn't do the trick on its own. One major note for why this exists in the docblocks is that changing the handling may lead to instances regenerating all processed files, which can be resource intense. We might not want to do this on a patch-level release. So maybe we can think about using Nicoles proposal as a 13.4 hotfix, and do the "breaking" change with a distinct follow-up in main. I do think this has larger implications and might break a 13.4 release with how we might need to fix this "properly".
  10. core-ci voted on patch set 3 V +1 07/01/25, 19:49 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/81201

  11. Nicole Hummel commented on patch set 3 07/01/25, 22:10

    Reply

    This is how the ImagePreviewContext works: only width and height properties are allowed and their values are casted as integers. The internal API uses those values as maximum values without further declaration. With the usage of \TYPO3\CMS\Core\Imaging\GraphicalFunctions::resize as streamline purpose the dedicated preview handling for the rendering process was removed but the calculation of the image size not adjusted. If you want to clean up the image preview handling you should remove

    Reply

    This is how the ImagePreviewContext works: only width and height properties are allowed and their values are casted as integers. The internal API uses those values as maximum values without further declaration. With the usage of \TYPO3\CMS\Core\Imaging\GraphicalFunctions::resize as streamline purpose the dedicated preview handling for the rendering process was removed but the calculation of the image size not adjusted. If you want to clean up the image preview handling you should remove the context and use the Image.CropScaleMask only
  12. Benjamin Franzke updated the commit message in patch set 4 V +1 07/02/25, 08:54

  13. Benjamin Franzke commented on patch set 4 CR +1 V +1 07/02/25, 08:54

    Reply

    alright, we should leave the patch as-is, thanks for the hint. So this "broke" with https://review.typo3.org/c/Packages/TYPO3.CMS/+/81107/8/typo3/sysext/core/Classes/Resource/Processing/LocalPreviewHelper.php Prior to that change Image.Preview used the imagemagick `-sample` [1] without `!` suffix, which therefore preserved aspect ratio. Btw, that's also the reason why the 12.4 backport for the ThumbnailViewHelperTest.php had to define other test assertions: https://review.typo3.org/c/Packages/TYPO3.CMS/+/84353/3#message-f3ce1bc72111f21191a185418839cf44d4a6f627 We're good to go here, thx! [1] https://usage.imagemagick.org/resize/#sample
  14. core-ci voted on patch set 4 V +1 07/02/25, 09:01 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/81238

  15. Benjamin Franzke commented on patch set 4 07/02/25, 09:02

    Reply

    and @garvin@hick.ing yes, since CONTEXT_IMAGEPREVIEW has no real advantage since 81107: [TASK] Centralize ImageMagick logic for FAL in GraphicalFunctions | https://review.typo3.org/c/Packages/TYPO3.CMS/+/81107 (it used to use the more performant, but low quality `sample` operator) we should indeed clean this up in `main` at some point and ideally ship upgrade wizards that migrate existing `CONTEXT_IMAGEPREVIEW` images to respective `CONTEXT_IMAGECROPSCALEMASK` to prevent regeneration of images. but that's for the future.
  16. Garvin Hicking voted on patch set 4 CR +1 V +1 07/02/25, 10:59

  17. Garvin Hicking voted on patch set 4 CR +2 V +2 07/02/25, 11:39

  18. Garvin Hicking merged patch set 5 07/02/25, 11:39