Project

General

Profile

Actions

Bug #91274

closed

Image composite operations fail with ImageMagick 7

Added by Alexander Nitsche over 4 years ago. Updated 4 months ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Image Generation / GIFBUILDER
Target version:
-
Start date:
2020-05-03
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
9
PHP Version:
7.3
Tags:
Complexity:
medium
Is Regression:
Sprint Focus:

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

  1. Run a TYPO3 instance with ImageMagick 7
  2. Navigate to TYPO3 Admin Panel > Environment > Image Processing and run the tests
  3. Check the test results: 4 tests have failed:
    1. Combine using a GIF mask with only black and white
    2. Combine using a JPG mask with graylevels
    3. Render text with TrueType font using 'niceText' option
    4. Render 'niceText' with a shadow under

Environment

  1. MariaDB 10.4.12
  2. Nginx 1.16.1
  3. PHP 7.3.17
  4. TYPO3 9.5.16
  5. 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

fails_1.png (146 KB) fails_1.png Fail - Combine using a GIF Alexander Nitsche, 2020-05-03 13:28
fails_2.png (135 KB) fails_2.png Fail - Combine using a JPG Alexander Nitsche, 2020-05-03 13:28
fails_3.png (88.2 KB) fails_3.png Fail - Render niceText Alexander Nitsche, 2020-05-03 13:28
succeeds_1.png (161 KB) succeeds_1.png Success - Combine using a GIF Alexander Nitsche, 2020-05-03 13:28
succeeds_2.png (150 KB) succeeds_2.png Success - Combine using a JPG Alexander Nitsche, 2020-05-03 13:28
succeeds_3.png (132 KB) succeeds_3.png Success - Render niceText Alexander Nitsche, 2020-05-03 13:28
fails_4.png (66.2 KB) fails_4.png Fail - Render text with TrueType Alexander Nitsche, 2020-05-03 13:31
succeeds_4.png (79.8 KB) succeeds_4.png Success - Render text with TrueType Alexander Nitsche, 2020-05-03 13:31

Updated by Alexander Nitsche over 4 years ago

Please find below the failing (+matte) tests:

  1. Combine using a GIF mask with only black and white
    Fail - Combine using a GIF
  2. Combine using a JPG mask with graylevels
    Fail - Combine using a JPG
  3. Render text with TrueType font using 'niceText' option
    Fail - Render text with TrueType
  4. Render 'niceText' with a shadow under
    Fail - Render niceText
Actions #2

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 .

Actions #3

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.

Actions #4

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.

Actions #5

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.

Actions #6

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)

Actions #7

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

Actions #8

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

Actions #9

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

Actions #10

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.

Actions #11

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
Actions #12

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

Actions #13

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

Actions #14

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

Actions #15

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

Actions #16

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

Actions #17

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

Actions #18

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

Actions #19

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

Actions #20

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 :)

Actions

Also available in: Atom PDF