Skip to content

Add ImageMagick support for image processing with GD fallback#40625

Open
Arro38 wants to merge 8 commits into
PrestaShop:developfrom
Arro38:feature/imagick-image-processing-engine
Open

Add ImageMagick support for image processing with GD fallback#40625
Arro38 wants to merge 8 commits into
PrestaShop:developfrom
Arro38:feature/imagick-image-processing-engine

Conversation

@Arro38
Copy link
Copy Markdown

@Arro38 Arro38 commented Jan 27, 2026

Questions Answers
Branch? develop
Description? Add ImageMagick (Imagick) as alternative image processing engine with GD fallback, and fix missing AVIF format in validation constants
Type? new feature
Category? CO
BC breaks? no
UI tests https://github.com/SiraDIOP/ga.tests.ui.pr/actions/runs/21628357206
Deprecations? no
Fixed ticket? N/A
How to test? See test plan below

Summary

  • Fix missing AVIF format in ImageManager::MIME_TYPE_SUPPORTED and EXTENSIONS_SUPPORTED constants — AVIF uploads were rejected by validation
  • Add ImageMagick (Imagick) as alternative image processing engine with automatic detection and GD fallback. Imagick provides higher quality resizing (Lanczos filter) and broader AVIF support
  • Update AvifExtensionChecker to detect Imagick AVIF support first, then fall back to GD
  • Add unit tests for all new Imagick methods (@requires extension imagick)

Changes

classes/ImageManager.php

  • Add image/avif to MIME_TYPE_SUPPORTED and avif to EXTENSIONS_SUPPORTED
  • Add isImagickAvailable() — cached static check for Imagick extension
  • Add resizeWithImagick() — full resize pipeline using Imagick with Lanczos filter, autoOrient(), canvas compositing (transparent for png/webp/avif, white for jpg)
  • Add writeImagick() — format-specific output with quality from PS_*_QUALITY config, progressive JPEG
  • Add getImagickSourceFileType() — maps Imagick format strings to IMAGETYPE_* constants
  • Extract calculateResizeDimensions() — shared between GD and Imagick paths
  • Extract getDestinationFileType() — shared file type resolution
  • Dispatch in resize(): try Imagick first, catch exceptions → fall back to GD

src/Core/Image/AvifExtensionChecker.php

  • Check Imagick AVIF support first (more efficient), then fall back to GD check

Tests

  • ImageManagerTest.php: add AVIF cases to existing data providers + isImagickAvailable test
  • ImageManagerImagickTest.php (new): 8 tests covering resizeWithImagick, writeImagick, calculateResizeDimensions, getImagickSourceFileType, auto-orientation

Architecture decision

Uses dispatch pattern (not strategy) because ImageManagerCore is a legacy static class with 22+ static callers. Zero API changes — all callers continue working unchanged. Same pattern as PrestaShop's Db class.

Test plan

  1. With Imagick installed: Upload a product image → verify jpg/webp/avif thumbnails generated with correct dimensions
  2. Without Imagick: Disable Imagick in php.ini → same test → verify GD fallback works transparently
  3. AVIF upload: Upload a .avif file as product image → should be accepted (was rejected before due to missing constant)
  4. Unit tests: composer run unit-tests — 32 tests, 53 assertions pass on PHP 8.4 + Imagick

coding974 added 4 commits January 27, 2026 21:37
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.
@Arro38 Arro38 requested a review from a team as a code owner January 27, 2026 20:17
@github-project-automation github-project-automation Bot moved this to Ready for review in PR Dashboard Jan 27, 2026
@ps-jarvis
Copy link
Copy Markdown

ps-jarvis commented Jan 27, 2026

Hi, thanks for this contribution!

Please consider opening an issue before submitting a Pull Request:

  • If it's a bug fix, it helps maintainers verify that the bug is effectively due to a defect in the code, and that it hasn't been fixed already.
  • It can help trigger a discussion about the best implementation path before a single line of code is written.
  • It may lead the Core Product team to mark that issue as a priority, further attracting the maintainers' attention.

(Note: this is an automated message, but answering it will reach a real human)

@ps-jarvis ps-jarvis added the develop Branch label Jan 27, 2026
@ps-jarvis
Copy link
Copy Markdown

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
Hlavtox previously approved these changes Jan 27, 2026
Copy link
Copy Markdown
Contributor

@Hlavtox Hlavtox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ps-jarvis ps-jarvis moved this from Ready for review to Need 2nd approval in PR Dashboard Jan 27, 2026
Codencode
Codencode previously approved these changes Jan 28, 2026
@ps-jarvis ps-jarvis added the Waiting for QA Status: action required, waiting for test feedback label Jan 28, 2026
@ps-jarvis ps-jarvis moved this from Need 2nd approval to To be tested in PR Dashboard Jan 28, 2026
@Progi1984 Progi1984 added this to the 9.2.0 milestone Jan 28, 2026
Touxten
Touxten previously approved these changes Jan 28, 2026
Hlavtox
Hlavtox previously approved these changes Jan 28, 2026
Copy link
Copy Markdown
Contributor

@Hlavtox Hlavtox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💣💣💣

@ps-jarvis ps-jarvis moved this from To be tested to Need 2nd approval in PR Dashboard Jan 28, 2026
Codencode
Codencode previously approved these changes Jan 28, 2026
@Touxten
Copy link
Copy Markdown
Contributor

Touxten commented Jan 30, 2026

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.
The image isn't created, but there is data in the database.

It works very well when I have Imagick.

2026-01-30.mp4

@Touxten
Copy link
Copy Markdown
Contributor

Touxten commented Feb 2, 2026

@Arro38
Thank you!
It seems to be working now, I'll resubmit a request for reviews.

2026-02-02.mp4

@Touxten Touxten requested review from Codencode and Hlavtox February 2, 2026 06:58
@Touxten Touxten removed Waiting for author Status: action required, waiting for author feedback Hook Contribution Waiting for QA Status: action required, waiting for test feedback labels Feb 2, 2026
@Touxten
Copy link
Copy Markdown
Contributor

Touxten commented Feb 2, 2026

cc @kpodemski for wording.

Codencode
Codencode previously approved these changes Feb 2, 2026
@ps-jarvis ps-jarvis moved this from Waiting for author to Need 2nd approval in PR Dashboard Feb 2, 2026
Hlavtox
Hlavtox previously approved these changes Feb 2, 2026
@ps-jarvis ps-jarvis added the Waiting for QA Status: action required, waiting for test feedback label Feb 2, 2026
@ps-jarvis ps-jarvis moved this from Need 2nd approval to To be tested in PR Dashboard Feb 2, 2026
@SiraDIOP SiraDIOP self-assigned this Feb 3, 2026
Copy link
Copy Markdown

@SiraDIOP SiraDIOP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @Arro38,

Thanks for your PR,

When imagick installed:
Capture d’écran 2026-02-03 à 14 10 08

Enregistrement.de.l.ecran.2026-02-03.a.14.16.07.mov
Capture d’écran 2026-02-03 à 14 21 13

When imagick not installed
Capture d’écran 2026-02-03 à 14 24 28

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

@Touxten
Copy link
Copy Markdown
Contributor

Touxten commented Feb 4, 2026

Thank you @SiraDIOP
You did not test the .avif format in the video.

Copy link
Copy Markdown

@SiraDIOP SiraDIOP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @Touxten,

My bad i forget the video

Image
Enregistrement.de.l.ecran.2026-02-04.a.14.44.44.mov

When imagick is desactived

Image
Enregistrement.de.l.ecran.2026-02-04.a.14.50.08.mov

Thank you

Copy link
Copy Markdown

@SiraDIOP SiraDIOP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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! 🙏

@SiraDIOP SiraDIOP added Waiting for author Status: action required, waiting for author feedback and removed Waiting for QA Status: action required, waiting for test feedback labels Feb 4, 2026
@ps-jarvis ps-jarvis moved this from To be tested to Waiting for author in PR Dashboard Feb 4, 2026
@Arro38
Copy link
Copy Markdown
Author

Arro38 commented Feb 5, 2026

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
supported MIME types in ImageManager::MIME_TYPE_SUPPORTED.

The issue:

  • The error message now includes image/avif in the allowed formats list
  • The test expects the old message (without AVIF) from boMyProfilePage.errorInvalidFormatImageMessage in the
    @prestashop-core/ui-testing package

The solution:
I can fix this test in two ways:

  1. Quick fix (in this PR): Update the test to check only the beginning of the error message, making it
    independent of the exact format list:
    expect(textResult).to.contains('Image format not recognized, allowed formats are:');

  2. Long-term fix: Update the @prestashop-core/ui-testing package to include AVIF in
    errorInvalidFormatImageMessage, but this requires a separate PR on that repository.

Which approach do you prefer? I'd suggest option 1 to unblock this PR quickly.

@Touxten Touxten removed the Waiting for author Status: action required, waiting for author feedback label Feb 11, 2026
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.
@Arro38 Arro38 dismissed stale reviews from Hlavtox and Codencode via b1c1375 February 16, 2026 16:28
@Arro38 Arro38 requested a review from a team as a code owner February 16, 2026 16:28
@Arro38
Copy link
Copy Markdown
Author

Arro38 commented Feb 28, 2026

Hi team! 👋 @Codencode @Touxten @SiraDIOP

Just a friendly bump on this PR. All 42 CI checks are now passing (including
the myProfile test that was previously failing).

This PR adds:

  • Imagick as an image processing engine (with GD fallback)
  • AVIF format support for both upload and thumbnail generation

Would appreciate a review when you get a chance. Thanks!

@Touxten
Copy link
Copy Markdown
Contributor

Touxten commented Feb 28, 2026

Hello @Arro38

@Codencode and I are external to PrestaShop. I will contact the PrestaShop team again.

Thank you for your patience.

@kpodemski kpodemski requested review from a team March 25, 2026 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

develop Branch

Projects

Status: Waiting for author

Development

Successfully merging this pull request may close these issues.

8 participants