Issue Bug Closed

#91274Image composite operations fail with ImageMagick 7

Alexander Nitsche 05/03/20, 13:24 updated 10/08/26, 10:23

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

Reviews 1

Files 8

History 1931

Show 6 earlier messages
  1. Alexander Nitsche commented and changed attached fails_1.png attached fails_2.png attached fails_3.png attached succeeds_1.png attached succeeds_2.png attached succeeds_3.png attached fails_4.png attached succeeds_4.png <span data-processor="relativetime" data-value="2020-05-03T13:36:23+00:00" > 05/03/20, 13:36 </span>

    Please find below the failing (+matte) tests:

    1. Combine using a GIF mask with only black and white
      fails_1.png
    2. Combine using a JPG mask with graylevels
      fails_2.png
    3. Render text with TrueType font using ‘niceText’ option
      fails_4.png
    4. Render ‘niceText’ with a shadow under
      fails_3.png
  2. Alexander Nitsche commented <span data-processor="relativetime" data-value="2020-05-03T19:43:47+00:00" > 05/03/20, 19:43 </span>

    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 .

  3. Alexander Nitsche commented <span data-processor="relativetime" data-value="2020-05-05T09:01:06+00:00" > 05/05/20, 09:01 </span>

    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.

  4. Alexander Nitsche commented <span data-processor="relativetime" data-value="2020-05-06T15:02:21+00:00" > 05/06/20, 15:02 </span>

    > 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.

  5. Alexander Nitsche commented <span data-processor="relativetime" data-value="2020-05-06T15:08:20+00:00" > 05/06/20, 15:08 </span>

    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.

  6. Bernd Wilke commented <span data-processor="relativetime" data-value="2022-11-11T07:44:57+00:00" > 11/11/22, 07:44 </span>

    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)

  1. Friedemann Altrock commented <span data-processor="relativetime" data-value="2023-09-26T15:26:50+00:00" > 09/26/23, 15:26 </span>

    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.

  2. Friedemann Altrock changed subject Admin tools: Image tests fail with ImageMagick 7 if using outdated +matte Image composite operations fail with ImageMagick 7 <span data-processor="relativetime" data-value="2023-09-26T15:32:02+00:00" > 09/26/23, 15:32 </span>

  3. Garvin Hicking commented and changed status Under Review Closed <span data-processor="relativetime" data-value="2024-08-02T20:52:12+00:00" > 08/02/24, 20:52 </span>

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

  4. Timo Webler commented <span data-processor="relativetime" data-value="2025-02-21T10:08:34+00:00" > 02/21/25, 10:08 </span>

    @ghi I have this issue on an current TYPO3 13.4.5 with ImageMagick 7 on Alpine(Docker). Same images from #91274#note-1

    /var/www/html$ magick --version
    Version: ImageMagick 7.1.1-41 Q16-HDRI x86_64 22504 https://imagemagick.org
    Copyright: (C) 1999 ImageMagick Studio LLC
    License: https://imagemagick.org/script/license.php
    Features: Cipher DPC HDRI Modules OpenMP(4.5)
    Delegates (built-in): bzlib cairo fftw fontconfig freetype gslib heic jng jpeg jxl lcms ltdl lzma pangocairo png ps raw rsvg tiff webp x xml zlib zstd
    Compiler: gcc (14.2)
    cat /etc/alpine-release
    3.21.3
    php -v
    PHP 8.3.17 (cli) (built: Feb 14 2025 19:22:04) (NTS)
    Copyright (c) The PHP Group
    Zend Engine v4.3.17, Copyright (c) Zend Technologies
        with Zend OPcache v8.3.17, Copyright (c), by Zend Technologies
  5. Friedemann Altrock commented <span data-processor="relativetime" data-value="2025-02-21T14:51:25+00:00" > 02/21/25, 14:51 </span>

    Hi @websi84,

    thanks for reviving this. I tried again to reproduce and managed on alpine 3.21. A semi-automated reproduction recipe can be found here: https://github.com/fwg/typo3-bugs/tree/forge/91274

    My findings so far:

    • the bug happens on Alpine 3.21 with the imagemagick package from APK
    • it also happens on Alpine 3.21 with ImageMagick compiled from source
    • it does not happen in the DDEV container with ImageMagick compiled from source.

    The DDEV container is based on Debian 12 at the moment. The only difference I can spot in the magick --version output is the GCC version – 14.2 on Alpine, 12.2 on Debian.

    In any case, the patch should probably be revived, as the added -type TrueColor does not impact IM 6.9 nor IM 7 on Debian.

  6. Riccardo De Contardi commented <span data-processor="relativetime" data-value="2025-02-21T14:57:09+00:00" > 02/21/25, 14:57 </span>

    Done. Restored as under review. Hope it is right for you

  7. Benni Mack commented <span data-processor="relativetime" data-value="2026-10-08T09:14:22+00:00" > 10/08/26, 09:14 </span>

    My take on this: The issue is fixed on current code, so this issue can be closed. It was fixed by #108933.

    What actually caused it: the combine (mask) command used +matte. ImageMagick 7 rejects that option and replaces it (option has been replaced ‘+matte’, use “-alpha Off”), so the masked image comes out wrong. Commit f57eb441967 (“[TASK] Create compatibility for ImageMagick 7”, Resolves #108933, Feb 2026) changed this. typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php:685 now uses -alpha off for ImageMagick and keeps +matte for GraphicsMagick.

  8. Benni Mack commented and changed status Under Review Closed <span data-processor="relativetime" data-value="2026-10-08T10:23:59+00:00" > 10/08/26, 10:23 </span>

    Closing this as it is fixed with #108933

    Your input here was really really important to figure out how to reproduce! Thank you.