Skip to content

Fix 6411 imagick gd fallback - #9909

Open
boredskull wants to merge 3 commits into
SimpleMachines:release-3.0from
boredskull:fix-6411-imagick-gd-fallback
Open

boredskull wants to merge 3 commits into
SimpleMachines:release-3.0from
boredskull:fix-6411-imagick-gd-fallback

Conversation

@boredskull

Copy link
Copy Markdown

Summary

This pull request addresses issue #6411, where SMF image processing can fail when ImageMagick is installed but lacks support for a particular image format.

Currently, SMF prioritises ImageMagick whenever the Imagick PHP extension is available. However, this does not guarantee that the installed ImageMagick configuration supports every image format.

As a result, operations such as uploading avatars, resizing images and generating attachment thumbnails can fail, even when the GD extension is available and capable of processing the image.

This PR introduces format detection and fallback handling to make image processing more reliable.

Changes Made

1. ImageMagick format detection

  • Uses Imagick::queryFormats() to identify formats supported by the installed ImageMagick configuration.
  • No longer assumes that every mapped image format is supported simply because Imagick is installed.
  • Caches the detected formats to avoid repeated queries.

2. GD fallback support

  • Detects supported image formats independently for both ImageMagick and GD.
  • Attempts processing through ImageMagick when the required formats are supported.
  • Falls back to GD when ImageMagick cannot process an image and GD supports both the source and destination formats.
  • Handles ImageMagick processing exceptions without immediately terminating the operation.

3. Improved image handling

  • Handles exceptions raised when ImageMagick attempts to open an image.
  • Allows the existing getimagesize() fallback to execute when ImageMagick cannot determine image dimensions.
  • Corrects GD format-function detection so it does not rely on the combined ImageMagick/GD supported-format list.
  • Preserves original image dimensions when re-encoding without specified size limits.
  • Adds protection against removing the original source image when cleaning up a failed ImageMagick operation.

Files Modified

Sources/Graphics/Image.php

The changes are contained within the existing image-processing class. No database changes, template modifications or additional dependencies are introduced.

Testing

Completed:

  • Reviewed the existing image-processing implementation.
  • Verified ImageMagick and GD capability-detection logic.
  • Verified that the GD fallback is attempted only when the required formats are supported.
  • Checked exception handling and source-file protection.
  • Confirmed that only Sources/Graphics/Image.php was modified.
  • Nine source-level assertions passed.

Further testing required:

  • Avatar uploads with unsupported ImageMagick formats.
  • Attachment thumbnail generation.
  • JPEG, PNG, GIF, BMP and WBMP processing.
  • ImageMagick failures where GD can successfully process the image.
  • Graceful failure where neither library supports the format.
  • Image re-encoding and preservation of original dimensions.

Full runtime and browser-based testing has not yet been completed in an environment with both Imagick and GD extensions installed.

Expected Result

SMF should continue to use ImageMagick where supported, but automatically attempt GD when ImageMagick cannot process a format that GD supports.

This should prevent avoidable image-processing failures and improve compatibility with hosting environments where ImageMagick has limited format support.

Issues References (Fixes|Related|Closes)

Related #6411

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant