Bug #91274
closedImage composite operations fail with ImageMagick 7
0%
Description
Problem/Description¶
The standard graphical functions class TYPO3\CMS\Core\Imaging\GraphicalFunctions fails to work properly with ImageMagick 7 (current major release) as it uses the outdated option +matte to remove the alpha layer in the output file instead of the more versatile option -alpha. See https://www.imagemagick.org/script/command-line-options.php#alpha for further details.
Affected example¶
- Run a TYPO3 instance with ImageMagick 7
- Navigate to TYPO3 Admin Panel > Environment > Image Processing and run the tests
- Check the test results: 4 tests have failed:
- Combine using a GIF mask with only black and white
- Combine using a JPG mask with graylevels
- Render text with TrueType font using 'niceText' option
- Render 'niceText' with a shadow under
Environment¶
- MariaDB 10.4.12
- Nginx 1.16.1
- PHP 7.3.17
- TYPO3 9.5.16
- ImageMagick 7.0.9-7 Q16 x86_64 2019-12-03
Checking the TYPO3 code base on GitHub this problem should be also reproducable on TYPO3 10.
Fixing the problem¶
I assume this problem can be either resolved by adding a hint in the TYPO3 docs and TYPO3 system tests that it does not support ImageMagick 7 at the moment
— or
by adding a switch to the TYPO3\CMS\Core\Imaging\GraphicalFunctions class which uses +matte or -alpha depending on the ImageMagick version (the history of ImageMagick has to be checked)
— or
by adding some smart switch to the TYPO3\CMS\Core\Imaging\GraphicalFunctions class which checks for the support of the feature +matte and -alpha of the installed ImageMagick/GraphicMagick and uses the one which is available.
Proof of Concept¶
Run the image tests and confirm that the 4 tests mentioned above fail. Replace all occurrences of +matte by -alpha off in TYPO3\CMS\Core\Imaging\GraphicalFunctions, run the image tests again and confirm that all tests succeed.
Greetings
Alex
Files
Updated by Alexander Nitsche over 4 years ago
- File fails_1.png fails_1.png added
- File fails_2.png fails_2.png added
- File fails_3.png fails_3.png added
- File succeeds_1.png succeeds_1.png added
- File succeeds_2.png succeeds_2.png added
- File succeeds_3.png succeeds_3.png added
- File fails_4.png fails_4.png added
- File succeeds_4.png succeeds_4.png added
Please find below the failing (+matte) tests:
- Combine using a GIF mask with only black and white
- Combine using a JPG mask with graylevels
- Render text with TrueType font using 'niceText' option
- Render 'niceText' with a shadow under
Updated by Alexander Nitsche over 4 years ago
I raised a question for clarification in the ImageMagick project as the command line option +matte should be still supported in ImageMagick 7 (though marked as deprecated) due to the ImageMagick docs. See https://github.com/ImageMagick/ImageMagick/issues/1974 .
Updated by Alexander Nitsche over 4 years ago
The deprecation warning "Replace +matte by -alpha off" is in ImageMagick docs since v6.7.6-0 (released in Mar 11, 2012) and as a general hint in the docs since at least ImageMagick v6.5.5 (May 9, 2009). The oldest maintained Linux distributions contain these ImageMagick versions:
- Debian 8 Jessie: v6.8.9
- Ubuntu 16 Xenial: v6.8.9
- RHEL 5: v6.2.8
- RHEL 6: v6.7.2
- CentOS 6: v6.7.2
- Open Suse Leap 15.1: v7.0.7
- SLES 11: v6.8.7
- Alpine 3.8: v7.0.8
Thus only RHEL 5 may not support -alpha off (maybe someone wants to check further in the ImageMagick6 project git history) but its end of Extended Life Cycle is end of this year (November 30, 2020).
Thus maybe the best solution here is to replace once all +matte by -alpha off for all maintained TYPO3 versions.
Updated by Alexander Nitsche over 4 years ago
Thus maybe the best solution here is to replace once all +matte by -alpha off for all maintained TYPO3 versions.
GraphicsMagick in contrary still supports +matte and does not support -alpha off . So +matte cannot be replaced by -alpha off as suggested before but each parameter has to be used conditionally.
Updated by Alexander Nitsche over 4 years ago
Btw, the latest GraphicsMagic of Alpine Linux (1.3.35 2020-02-23 Q16) did not blur the shadow for the last test "Render 'niceText' with a shadow under" which could be fixed by setting the TYPO3 configuration option $GLOBALS['TYPO3_CONF_VARS']['GFX']['processor_effects']=true . Maybe one wants to have a look again at the regarding info text of the test which says
Note on 'shadow'
This test makes sense only if the above test had a correct output. But if so, you may not see a soft dropshadow from the third text string as you should. In that case you are most likely using ImageMagick 5 and should set the flag $GLOBALS['TYPO3_CONF_VARS']['GFX']['processor_effects'].
as it gave me the impression that this option is mainly for backwards compatibility.
Updated by Bernd Wilke about 2 years ago
Meanwhile (2022-11-11) the current documentation of imagemagick (version 7) states (https://imagemagick.org/script/command-line-options.php#alpha):
Note that while the obsolete +matte operation was the same as "-alpha Off", the >-matte operation was the same as "-alpha Set" and not "-alpha On".
(Tested with TYPO3 11.5.18, PHP 8.0.24, ImageMagick 7.1.0-9)
Updated by Gerrit Code Review about 1 year ago
- Status changed from New to Under Review
Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/81255
Updated by Gerrit Code Review about 1 year ago
Patch set 2 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/81255
Updated by Gerrit Code Review about 1 year ago
Patch set 3 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/81255
Updated by Friedemann Altrock about 1 year ago
I have made a patch that can be applied with composer-patches: https://github.com/TYPO3/typo3/commit/6c675a3e50da48a592384cd6146e16e54379bc01
Unfortunately there was some really old code from 2010 in \TYPO3\CMS\Core\Utility\CommandUtility::imageMagickCommand
which rearranged the command line parameters in case of a composite operation. Because somebody out there maybe calls imageMagickCommand
directly and relied on this behaviour, this patch is a breaking change and can only be applied for version 13.
Updated by Friedemann Altrock about 1 year ago
- Subject changed from Admin tools: Image tests fail with ImageMagick 7 if using outdated +matte to Image composite operations fail with ImageMagick 7
Updated by Gerrit Code Review about 1 year ago
Patch set 4 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/81255
Updated by Gerrit Code Review about 1 year ago
Patch set 5 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/81255
Updated by Gerrit Code Review about 1 year ago
Patch set 6 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/81255
Updated by Gerrit Code Review 10 months ago
Patch set 7 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/81255
Updated by Gerrit Code Review 4 months ago
Patch set 8 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/81255
Updated by Gerrit Code Review 4 months ago
Patch set 9 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/81255
Updated by Gerrit Code Review 4 months ago
Patch set 10 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/81255
Updated by Gerrit Code Review 4 months ago
Patch set 11 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/81255
Updated by Garvin Hicking 4 months ago
- Status changed from Under Review to Closed
Closing the issue due to not being reproducible on main (v13) any more, as per patch: https://review.typo3.org/c/Packages/TYPO3.CMS/+/81255
If I made a mistake, please get in touch :)