Skip to content

[6.x] Skip driver check for universally supported image formats - #15665

Open
daun wants to merge 2 commits into
statamic:6.xfrom
daun:perf/skip-common-image-format-support-check
Open

daun wants to merge 2 commits into
statamic:6.xfrom
daun:perf/skip-common-image-format-support-check

Conversation

@daun

@daun daun commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Skip the image driver's format check for JPG, JPEG, PNG and GIF in ImageValidator::isValidExtension().

Problem

With the Imagick driver, $driver->supports($extension) calls Imagick::queryFormats(). The first call in a PHP process takes a good 400ms while ImageMagick loads its format modules.

The memo from #15449 only helps within a single request, because the memoized static property is reset after each one. The check is still done by every artisan command, queue:listen job, static:warm run and test run, and on the first request in each PHP-FPM worker.

Fix

GD and Imagick can both read JPG, JPEG, PNG and GIF, so isValidExtension() now returns true for those without asking the driver. Most calls are for these formats, so requests not generating WEBP or AVIF urls should never pay the ImageMagick format check at all. Other extensions (webp, avif, svg, heic, tiff, pdf, …) still go through the driver check and the memo. isValidImage() still checks the MIME type for every extension.

Trade-off

A GD or ImageMagick build without JPEG/PNG support would now report those formats as valid. I'm pretty sure that's not a realistic setup in the wild, though :) Debian, Ubuntu, Homebrew all have those formats enabled, and Forge, Ploi, Plesk all install from those packages. GIF support is hardwired into both, interestingly.

Tests

  • supports() is never called for jpg, JPG, jpeg, png and gif, and all of them return true
  • Empty and null extensions still return false
  • A JPG/PNG with the wrong MIME type is still rejected

@daun daun changed the title [6.x] Skip driver probe for universally supported image formats [6.x] Skip driver check for universally supported image formats Oct 17, 2026

This branch has not been deployed

No deployments
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