Add ImageMagick support for image processing with GD fallback#40625
Add ImageMagick support for image processing with GD fallback#40625Arro38 wants to merge 8 commits into
Conversation
Add 'image/avif' to MIME_TYPE_SUPPORTED and 'avif' to EXTENSIONS_SUPPORTED so that AVIF uploads pass validation. Previously, AVIF files were rejected despite write() already supporting imageavif() output.
When the Imagick PHP extension is available, ImageManager::resize() now delegates to a new resizeWithImagick() path that uses Lanczos filtering for better quality. On any Imagick failure, the method falls back to the existing GD code path transparently. Shared logic (dimension calculation, destination file type resolution) is extracted into calculateResizeDimensions() and getDestinationFileType() to avoid duplication between the two engines.
Imagick is now checked first since it has broader AVIF support and is the preferred image processing engine. GD is only tested as a fallback. This ensures the back-office correctly shows AVIF as available on hosts where Imagick supports it even if GD does not.
Tests cover writeImagick for each format (jpg, png, gif, webp, avif), calculateResizeDimensions, getImagickSourceFileType, isImagickAvailable, EXIF auto-orientation, and JPEG output validity. The test class requires the imagick extension and pre-populates Configuration cache to avoid DB access.
|
Hi, thanks for this contribution! Please consider opening an issue before submitting a Pull Request:
(Note: this is an automated message, but answering it will reach a real human) |
|
Hello @Arro38! This is your first pull request on PrestaShop repository of the PrestaShop project. Thank you, and welcome to this Open Source community! |
Hlavtox
left a comment
There was a problem hiding this comment.
Hello @Arro38, what a great job!!!
I will approve, just one wish. Please keep the comments I added regarding the JPG/PNG combo and transparecy. 🙏
/*
* If the filetype is not forced and we are requesting a JPG file, we will adjust the format inside
* the image according to PS_IMAGE_QUALITY in some cases.
*/
// If PS_IMAGE_QUALITY is set to png_all, we will use PNG file no matter the
// If PS_IMAGE_QUALITY is set to png (optional), we will use PNG if the original format could support transparency.|
Hello @Arro38 I did a little test, and here's what came out in the video. When I don't have Imagick, I can still import an AVIF image with an error. It works very well when I have Imagick. 2026-01-30.mp4 |
|
@Arro38 2026-02-02.mp4 |
|
cc @kpodemski for wording. |
There was a problem hiding this comment.
Hello @Arro38,
Thanks for your PR,
Enregistrement.de.l.ecran.2026-02-03.a.14.16.07.mov
Enregistrement.de.l.ecran.2026-02-03.a.14.27.41.mov
Thanks
I'm waiting automated tests to approve the PR
https://github.com/SiraDIOP/ga.tests.ui.pr/actions/runs/21628357206
|
Thank you @SiraDIOP |
SiraDIOP
left a comment
There was a problem hiding this comment.
Hello @Arro38,
I ran the automated tests, but they are still red.
After discussing with the automated QA team, it seems that the problem comes from this file:
``tests/UI/campaigns/functional/BO/15_header/07_myProfile.ts
Can you please check it?
Thanks in advance! 🙏
Hi @SiraDIOP ! Yes, I checked the test. The failure is expected because this PR adds AVIF support, which modifies the list of The issue:
The solution:
Which approach do you prefer? I'd suggest option 1 to unblock this PR quickly. |
The error message assertion now checks only the beginning of the message, making it independent of the exact list of supported MIME types. This is needed because image/avif was added to ImageManager::MIME_TYPE_SUPPORTED.
|
Hi team! 👋 @Codencode @Touxten @SiraDIOP Just a friendly bump on this PR. All 42 CI checks are now passing (including This PR adds:
Would appreciate a review when you get a chance. Thanks! |
|
Hello @Arro38 @Codencode and I are external to PrestaShop. I will contact the PrestaShop team again. Thank you for your patience. |



Summary
ImageManager::MIME_TYPE_SUPPORTEDandEXTENSIONS_SUPPORTEDconstants — AVIF uploads were rejected by validationAvifExtensionCheckerto detect Imagick AVIF support first, then fall back to GD@requires extension imagick)Changes
classes/ImageManager.phpimage/aviftoMIME_TYPE_SUPPORTEDandaviftoEXTENSIONS_SUPPORTEDisImagickAvailable()— cached static check for Imagick extensionresizeWithImagick()— full resize pipeline using Imagick with Lanczos filter,autoOrient(), canvas compositing (transparent for png/webp/avif, white for jpg)writeImagick()— format-specific output with quality fromPS_*_QUALITYconfig, progressive JPEGgetImagickSourceFileType()— maps Imagick format strings toIMAGETYPE_*constantscalculateResizeDimensions()— shared between GD and Imagick pathsgetDestinationFileType()— shared file type resolutionresize(): try Imagick first, catch exceptions → fall back to GDsrc/Core/Image/AvifExtensionChecker.phpTests
ImageManagerTest.php: add AVIF cases to existing data providers +isImagickAvailabletestImageManagerImagickTest.php(new): 8 tests coveringresizeWithImagick,writeImagick,calculateResizeDimensions,getImagickSourceFileType, auto-orientationArchitecture decision
Uses dispatch pattern (not strategy) because
ImageManagerCoreis a legacy static class with 22+ static callers. Zero API changes — all callers continue working unchanged. Same pattern as PrestaShop'sDbclass.Test plan
.aviffile as product image → should be accepted (was rejected before due to missing constant)composer run unit-tests— 32 tests, 53 assertions pass on PHP 8.4 + Imagick