Review main Abandoned

65088[BUGFIX] Apply quality constraint to processed images only once

Andreas Kienast CR 0 V 0 Easy +1 −4 updated 08/05/20, 11:25

Commit message

This patch changes the behavior of LocalCropScaleMaskHelper to not
shrink the image quality for its initial crop action anymore.

The issue was that the cropped variant of an image had a quality
constraint. The quality of that very image got worse in the further
processings as the same quality constraint was applied again.

The method `GraphicalFunctions::imageMagickConvert()` accepts the
arguments `$params` which is empty if the image processing configuration
doesn't include an `additionalParameters` element containing ImageMagick
parameters, which is nowhere defined in TYPO3 Core.

`GraphicalFunctions` defines a set of parameters applied by default, see
its constructor, and `$this->cmds`. One of those default parameters is
`-quality`.
If `GraphicalFunctions::imageMagickConvert` is called with an empty
`$params` attribute, these defaults get applied which lead to reducing
the image quality again.

Review

  • Code review CR 0
  • Verified V 0

Issues 1

Files 1

Review log 1520

  1. Andreas Kienast uploaded patch set 1 07/25/20, 07:40

  2. TYPO3com voted on patch set 1 V -1 07/25/20, 07:41 Completed build in 20s on Sat, 25 Jul, 07:41 AM Test Summary: No tests found Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-4233

  3. Andreas Kienast updated the commit message in patch set 2 07/25/20, 07:41

  4. TYPO3com voted on patch set 2 V -1 07/25/20, 07:42 Completed build in 20s on Sat, 25 Jul, 07:42 AM Test Summary: No tests found Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-4234

  5. Andreas Kienast uploaded patch set 3 07/25/20, 07:42

  6. Andreas Kienast updated the commit message in patch set 4 07/25/20, 07:44

  7. Anja Leichsenring updated the commit message in patch set 5 07/25/20, 07:48

  8. TYPO3com voted on patch set 3 V +1 07/25/20, 07:55 Completed build in 12m 50s on Sat, 25 Jul, 07:55 AM Test Summary: 72921 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-4235

  9. TYPO3com voted on patch set 4 V +1 07/25/20, 07:58 Completed build in 13m 57s on Sat, 25 Jul, 07:58 AM Test Summary: 72921 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-4236

  10. TYPO3com voted on patch set 5 V +1 07/25/20, 08:02 Completed build in 13m 23s on Sat, 25 Jul, 08:02 AM Test Summary: 72921 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-4237

  11. Christian Toffolo commented on patch set 5 07/26/20, 11:27

    LocalCropScaleMaskHelper.php:92

    Removing -quality parameter, ImageMagick will use the default quality that is 92 (http://www.imagemagick.org/script/command-line-options.php#quality). For optimal result please force '-quality 100'.
  12. Helmut Hummel commented on patch set 5 CR -1 07/26/20, 14:36

    What happens, if there is NO further processing of the image?

    LocalCropScaleMaskHelper.php:92 Reply Unresolved

    More importantly: removing this option here results in quality definition not applied any more at all, when no further processing is applied
  13. Andreas Kienast commented on patch set 5 07/26/20, 17:49

    Reply

    If I read the code correctly, this is the case if we handle SVGs (which don't get converted) or when generating masks that don't base on FAL assets. How likely is it this will happen and how would we make this more predictable?
  14. Helmut Hummel commented on patch set 5 07/27/20, 11:40

    Reply

    One thing that is a bit tricky here indeed is "reading the code correctly". What I see at least, is, that this class does only handle assets based on FAL, as the incoming argument is a Task. To fix this issue, I'd argue we'd need to do a bit more than just removing the quality constraint from one call, but rather (re-)conceptualize demands and expected outcome for different scenarios and then apply this concept to the code. I argue like that, because this issue and the attempt to fix it raises a couple of questions, that aren't easy to answer without doing a conceptual step: 1. Should the default quality of 92% be used or rather 100% in the first processing? 2. Is there a case where the cropped image isn't processed any further, leading to be stuck with the initial quality? 3. Does the double processing cause quality loss even with higher quality in the first step and can we probably apply all processing in one step instead? 4. What other types of processing happen (or not happen when svg) and does how are they affected? Looking into GraphicalFunctions::imageMagickConvert e.g. indeed reveals that a crop might be applied again, when provided with width and height options. So this would be the appropriate place to fix, although much more complicated of course. Last but not least, here one example that would cause another bug, when applying this change proposal (based on my understanding of the current code): An image has crop instructions, but no other processing instructions. Then the second call to imageMagickConvert will return early without any additional processing being applied, resulting in a final image with 100% quality, which I think isn't the desired outcome.
  15. Helmut Hummel commented on patch set 5 V -1 07/28/20, 12:56

    > Last but not least, here one example that would cause another bug, when applying this change proposal (based on my understanding of the current code): I debugged my way through the code using the given example. Code path is indeed like predicted. Processing happens only once when only a crop instruction is present, leading to an resulting image that hasn't the configured quality.
  16. Helmut Hummel commented on patch set 5 07/29/20, 12:22

    Found this https://review.typo3.org/c/Packages/TYPO3.CMS/+/56779/, which explixitly introduced the quality option
  17. Christian Toffolo commented on patch set 5 07/30/20, 10:46

    Reply Unresolved

    I answer here what I can after having debugged the code... 1. If you can choose the quality for a temporary JPG image why you should even consider a quality < 100? 2. Debugging the code I can't find a case where the eventually cropped image (first time JPG compressed image) isn't compressed again. Both masked and not masked will pass again into imageMagickConvert 3. A 100% quality JPG practically doesn't change the pixels of the image, at least not in a human perceivable way. Try comparing an original image with its 100% JPG conversion, max zooming in, there's no difference at pixels level. 4. in case of a cropped SVG a tmp PNG is used instead of JPG so no problem because PNG is lossless.
  18. Christian Toffolo commented on patch set 5 07/30/20, 10:51

    > Patch Set 5: Verified-1 > > > Last but not least, here one example that would cause another bug, when applying this change proposal (based on my understanding of the current code): > > I debugged my way through the code using the given example. Code path is indeed like predicted. Processing happens only once when only a crop instruction is present, leading to an resulting image that hasn't the configured quality. Please, can you give me some direction to reproduce this case? Because of what I tried, the JPG cropped image always is passed to imageMagickConvert after.
  19. Helmut Hummel commented on patch set 5 CR -2 08/05/20, 11:24

  20. Helmut Hummel abandoned the change 08/05/20, 11:25