GD ships with PHP, resizes and crops JPEG, PNG, GIF and WebP quickly, and allocates its pixel buffer inside PHP’s own heap — so a runaway image gives you a PHP fatal, not a dead worker. Imagick is a PECL wrapper around the ImageMagick C library: many more formats, real ICC colour management, sharper downscales, and a much larger attack surface, with its memory sitting outside memory_limit entirely. If your pipeline only makes thumbnails out of JPEG and PNG uploads, GD is enough and is the safer default on a shared box. If you have to read PDF, TIFF, HEIC or camera RAW, or keep colour honest, Imagick is the only choice — and it needs a policy file you have actually read. This page explains the mechanism behind that split, gives you a decision rule, and shows you how to verify what your server, and your WordPress install, are really using.
What you’ll accomplish
- A confirmed answer to which extensions your PHP build has loaded, and what they were compiled against.
- The ImageMagick version and delegate list actually sitting behind Imagick — which is the version that matters, not the PECL one.
- A reading of the effective
policy.xml, so you know which coders and resource ceilings apply before you write code against them. - The image editor class WordPress has chosen, and a deliberate way to force the other one.
- A rule you can defend for each pipeline, instead of using whichever extension the last developer reached for.
Prerequisites
Assume PHP 8.0 or newer and shell access to the server. Version differences are real here: GD gained WebP support in PHP 7.0 (when built against libwebp), BMP in 7.2, and AVIF in 8.1 (when built against libavif). Anything older and the format table below stops applying.
On the Imagick side, the PECL extension version — 3.7.x at the time of writing — tells you very little. What matters is the ImageMagick library it was built against and is running against, because format coverage, resource behaviour and the policy file all come from there. ImageMagick 6 and 7 read different config directories, and a server can easily have an IM 7 command line and an IM 6 PHP extension.
The command-line policy reader below works without root; reading /etc/ImageMagick-6/policy.xml or /etc/ImageMagick-7/policy.xml directly usually does not. On cPanel, extensions are enabled per PHP version rather than globally, so php -m on the shell can disagree with what the site actually sees. For the WordPress checks you need WP-CLI, or admin access to Site Health.
How it works
Both extensions do the same three things: decode a compressed file into a raster, transform it, re-encode it. The difference that decides almost every argument is where that raster lives.
GD is compiled into PHP against libgd. With PHP’s bundled libgd — the default for most builds — the decoded image is allocated through PHP’s own allocator, as roughly width × height × 4 bytes for a truecolour image, allocated in one go before any resizing happens. A 6000 × 4000 phone photo is therefore about 96 MB of heap the moment imagecreatefromjpeg() returns, whatever the JPEG weighed on disk. Because it is PHP’s heap, memory_get_usage() sees it and memory_limit caps it. An oversized upload produces Allowed memory size of N bytes exhausted, the request dies, and the FPM worker carries on serving.
Imagick behaves differently at every one of those points. It is a thin wrapper over MagickWand, and the pixels live in ImageMagick’s own pixel cache, allocated by MagickCore outside PHP’s allocator. PHP cannot see it and memory_limit does not bound it. The control that does is ImageMagick’s resource policy: the cache uses heap memory up to the memory limit, then spills to a memory-mapped file up to the map limit, then to a plain temporary file up to the disk limit, and only fails when all three are exhausted. That spill is why an Imagick job can quietly fill a temp filesystem instead of erroring, and why memory_get_usage() can report a few megabytes while the process RSS is several hundred.
The second structural difference is surface area. GD understands a short, fixed list of formats compiled into it, and does nothing else. ImageMagick understands hundreds, several of them by shelling out to delegate programs — Ghostscript for PostScript and PDF being the notorious one. That is exactly the surface that produced the 2016 coder vulnerabilities, and it is why almost every distribution now ships a policy.xml that revokes rights on the PS, EPS, PDF and XPS coders and on the gs delegate. Those policy.xml entries also act as ceilings for the resource limits: raising a limit at runtime through Imagick::setResourceLimit() or a MAGICK_MEMORY_LIMIT environment variable will not lift a lower value the policy has already set.
Third, process safety. GD is single-threaded and in-process. ImageMagick is often built with OpenMP and will use several threads per operation, which is wasted work inside an FPM worker and a source of contention when a dozen workers do it at once. The Imagick extension ships an INI setting, imagick.set_single_thread, that pins it to one thread; recent builds default it on. When ImageMagick does fail hard it takes the whole worker with it — a SIGSEGV in a delegate is a 502 for whoever was on that worker, not a catchable PHP exception.
| GD | Imagick | |
|---|---|---|
| Ships with PHP | Yes, bundled | No, PECL + ImageMagick |
| Version that matters | PHP’s, and libgd’s | ImageMagick’s |
| Pixel memory | PHP heap, counted | MagickCore cache, uncounted |
| Bounded by | memory_limit | policy.xml resource limits |
| Reads | JPEG, PNG, GIF, WebP, AVIF, BMP, XBM | Whatever the delegates allow: adds TIFF, PDF, SVG, HEIC, RAW, EPS |
| ICC profiles | Discarded on decode | Read, kept, or converted |
| EXIF orientation | Ignored, you rotate yourself | Readable via the image orientation property |
| Downscale filter | IMG_BILINEAR_FIXED default, IMG_BICUBIC_FIXED available | Full filter set, Imagick::FILTER_LANCZOS and friends |
| Chroma subsampling | No control | setSamplingFactors() |
| Failure mode | PHP fatal, worker survives | OOM kill or segfault, worker dies |
Step-by-step
-
Confirm which extensions PHP has actually loaded. Run this for the exact binary the site uses, not just the default one on
PATH.php -m | grep -Ei '^(gd|imagick)$'Expected output is one or both names, one per line:
gd imagickNothing at all means neither is present and every image call in the codebase is fatal. Only
gdis the common case on a stock distribution PHP. -
Read what GD was built with. The support flags matter more than the version number.
php --ri gdYou are looking for the
Supportlines:GD Support => enabled GD library Version => 2.3.3 JPEG Support => enabled PNG Support => enabled WebP Support => enabled AVIF Support => enabledA
WebP Supportline readingdisabled, or noAVIF Supportline at all, meansimagewebp()orimageavif()will not do what you expect on this build regardless of PHP version. -
Read the ImageMagick behind Imagick. This is the single most useful command on the page.
php --ri imagickExpected output includes two version lines that should agree, plus the format list and the INI directives:
imagick module version => 3.7.0 Imagick compiled with ImageMagick version => ImageMagick 6.9.11-60 Q16 Imagick using ImageMagick library version => ImageMagick 6.9.11-60 Q16 ImageMagick number of supported formats: => 242 imagick.set_single_thread => 1 => 1If the
compiled withandusinglines name different versions, the extension is running against a library it was not built for — rebuild it before you trust anything else here. Note theQ16marker: a Q16 build stores 16 bits per channel, so its pixel cache is twice the size of a Q8 build’s for the same image. -
Read the delegates the ImageMagick build actually has. Format support is not a property of Imagick; it is a property of this build.
magick -version || convert -versionExpected output ends with a delegate list. HEIC, WebP and TIFF are the ones worth checking for:
Version: ImageMagick 6.9.11-60 Q16 x86_64 Delegates (built-in): bzlib fftw fontconfig freetype heic jng jp2 jpeg lcms lqr ltdl lzma openexr pangocairo png tiff webp wmf x xml zliblcmsin that list is what makes ICC conversion possible. If it is absent, Imagick can carry a profile but not convert with it. Beware that the command line may be a different major version than the PHP extension reported in step 3. -
Read the effective policy and resource ceilings. These apply to PHP too, not only to the command line.
magick identify -list policy || identify -list policyA typical distribution policy looks like this, trimmed:
Path: /etc/ImageMagick-6/policy.xml Policy: Resource name: memory value: 256MiB Policy: Coder rights: None pattern: PDF Policy: Delegate rights: None pattern: gsThen read the limits as ImageMagick resolved them:
magick identify -list resource || identify -list resourceResource limits: Width: 107.374MP Height: 107.374MP Area: 2.1474GP Memory: 256MiB Map: 512MiB Disk: 1GiB Thread: 1 Time: unlimitedThose numbers, not
memory_limit, are what stops a hostile or merely enormous upload. ImageMagick documents the file and its options on its security policy page. -
Ask WordPress which editor it picked. WordPress does not use GD or Imagick directly; it picks an implementation of
WP_Image_Editorat runtime._wp_image_editor_choose()walks the list returned by thewp_image_editorsfilter — by defaultWP_Image_Editor_ImagickthenWP_Image_Editor_GD— and takes the first whosetest()andsupports_mime_type()both pass. Imagick therefore wins whenever it is installed and functional.wp eval 'echo get_class( wp_get_image_editor( ABSPATH . "wp-includes/images/media/default.png" ) ), "\n";'Expected output is one class name:
WP_Image_Editor_ImagickWithout WP-CLI, Tools → Site Health → Info has a media handling panel naming the active editor and the ImageMagick version. You can also ask about a specific output format:
wp eval 'var_dump( wp_image_editor_supports( array( "mime_type" => "image/webp" ) ) );'bool(true) -
Settle which one you want before you change anything. Work down these questions in order; the first yes is your answer.
-
Force the editor deliberately, in an mu-plugin. Putting this in a theme means it disappears at the next theme switch.
mkdir -p wp-content/mu-plugins && wp eval 'file_put_contents( WPMU_PLUGIN_DIR . "/force-gd-editor.php", "<?php add_filter( \"wp_image_editors\", function() { return array( \"WP_Image_Editor_GD\" ); } );" );'Re-run the check from step 6. Expected output changes to:
WP_Image_Editor_GDReturning a single-element array is the point: it removes Imagick from consideration rather than reordering it. To go the other way, return
array( 'WP_Image_Editor_Imagick' )and WordPress will fail loudly if Imagick is missing instead of silently falling back. -
Set Imagick’s own limits in code where the policy allows it. A policy ceiling cannot be raised from PHP, but it can be lowered, which is what you want for a worker that handles untrusted uploads.
php -r ' Imagick::setResourceLimit( Imagick::RESOURCETYPE_MEMORY, 128 * 1024 * 1024 ); Imagick::setResourceLimit( Imagick::RESOURCETYPE_MAP, 256 * 1024 * 1024 ); Imagick::setResourceLimit( Imagick::RESOURCETYPE_THREAD, 1 ); $i = new Imagick(); $i->setOption( "jpeg:size", "1600x1600" ); $i->readImage( "/tmp/big.jpg" ); $rows = (int) round( $i->getImageHeight() * 800 / $i->getImageWidth() ); $i->resizeImage( 800, $rows, Imagick::FILTER_LANCZOS, 1 ); $i->setImageCompressionQuality( 82 ); $i->setSamplingFactors( array( "2x2", "1x1", "1x1" ) ); $i->stripImage(); $i->writeImage( "/tmp/out.jpg" ); $i->destroy(); echo "ok\n"; 'Expected output is
ok. Thejpeg:sizeoption is the important line: it tells the JPEG decoder to scale during decode, so a 24-megapixel source never fully materialises in the cache. Callingdestroy()rather than waiting for the destructor is what returns that cache promptly inside a long-lived worker.
Validate it works
Prove the memory claim rather than believing it. Run each pipeline under /usr/bin/time -v on Linux and compare what PHP reports with the process’s real peak.
/usr/bin/time -v php -r '
$img = imagecreatefromjpeg( "/tmp/big.jpg" );
imagejpeg( imagescale( $img, 800, -1, IMG_BICUBIC_FIXED ), "/tmp/gd.jpg", 82 );
printf( "php peak: %.1f MiB\n", memory_get_peak_usage( true ) / 1048576 );
' 2>&1 | grep -E 'php peak|Maximum resident'
For a 24-megapixel JPEG the two numbers track each other closely — PHP’s peak is most of the RSS, because the buffer is in PHP’s heap. Repeat with the Imagick snippet from step 9 and the two numbers diverge sharply: PHP’s peak stays small while Maximum resident set size climbs into the hundreds of megabytes. That gap is the whole argument.
Then confirm the WordPress side end to end by regenerating one attachment and listing the files it produced:
wp media regenerate 123 --yes && ls -1 wp-content/uploads/2026/09/ | grep -c 'x[0-9]*\.'
A non-zero count means the chosen editor produced sub-sizes successfully.
Troubleshooting
-
ImagickException: not authorized. The coder policy blocked the format, almost alwaysPDF,PSorEPS. Confirm with step 5. The correct fix is rarely to delete the policy line; it is to convert the file outside the web request, in a queue worker with its own tightened policy, or to reject the format at upload. -
WordPress reports an HTTP error or post-processing failure on upload. Large images pass the upload but die during sub-size generation, and the usual cause is Imagick hitting a resource ceiling or an OOM kill mid-request. The failure looks like a browser-side upload problem and is not one — walk the server-side causes in HTTP error on WordPress media upload before touching the extension.
-
Allowed memory size of N bytes exhaustedinsideimagecreatefromjpeg(). This is GD behaving correctly. Read dimensions before decoding withgetimagesize(), reject anything past a sane megapixel ceiling, and only then raisememory_limit. -
FPM logs
child NNNN exited on signal 11 (SIGSEGV)during image work. An ImageMagick delegate or a corrupt input crashed the worker. Setimagick.set_single_thread=1, confirm the compiled-against and running-against versions in step 3 match, and move the work out of the request path. -
imagewebp()writes a file nothing can open. GD was built without libwebp. Checkphp --ri gdforWebP Support => enabledrather than trusting the function’s existence.
When this is the wrong approach
Neither extension is the right tool for bulk conversion of an existing library. Ten thousand images do not belong in PHP requests at all; run the ImageMagick command line, or a dedicated encoder, from a queue.
Switching extensions is also the wrong fix for slow pages. If images arrive as 2 MB JPEGs, the win is in output format and delivery, not in which library resized them — that work is covered in WebP and AVIF image optimization. And on a multi-tenant server, relaxing policy.xml so one site can make PDF thumbnails changes the security posture for every account on the box.
Finally, do not install Imagick “just in case”. An extension you do not need is an attack surface you did not have to accept, and on WordPress it silently becomes the active editor the moment it loads.
The PHP manual’s Imagick book is the reference for the API surface, and ImageMagick’s own documentation is authoritative on resource and policy behaviour.
Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under Enterprise WordPress; book an infrastructure consult.