Make WordPress Core

Opened 5 months ago

Last modified 4 weeks ago

#65473 new enhancement

Feature: Add libvips-based Image Editor to WP Core

Reported by: nickchomey Owned by:
Priority: normal Milestone: Awaiting Review
Component: Media Version: 7.1
Severity: normal Keywords: has-patch has-unit-tests
Cc: Focuses: performance, sustainability

Description (last modified by nickchomey)

WP 7.1 is taking a big step forward with regards to Media processing with the ​client-side media processing effort. I see this as an opportunity make significant improvements to server-side media processing at the same time.

Problem: WordPress Media Processing requires excessive server resources

It is common for users to report issues and failures with uploading images (e.g. #23127, #22869, #48522, #55289), and these largely come down to running out of RAM.

@kirasong confirmed to me recently ​in slack that:

image processing has been the highest user of RAM for any individual operation in WordPress for as long as I've been working on the project

Reducing the memory requirements of image processing would improve reliability on resource-constrained hosting environments and allow available memory to be used for serving requests rather than generating image subsizes.

Finally, datacenter CO2 emissions are becoming an increasingly pressing concern. So, WordPress - representing over 40% of the web - needs to endeavour to reduce its server footprint as much as possible.

Proposal: Add WP Core support for using ​libvips to process images on the server

Published ​libvips benchmarks show memory usage and processing times that are often 10–20x lower than ImageMagick and GD. My own testing of libvips for WordPress media uploads has shown improvements in the 5x range for CPU (measuring memory usage seems tricky for Imagick and VIPS, so I don't have figures on hand).

Using libvips in WP Core would result in faster and more reliable uploads, fewer user errors and support/trac tickets, lower memory requirements, reduced hosting costs, lower CO2 emissions, and more.

We should introduce a new WP_Image_Editor_Vips implementation in wp/wp-includes/class-wp-image-editor-vips.php, which would use ​php-vips to talk to libvips via the php FFI extension. This would be the preferred Image Editor, falling back gracefully to Imagick when libvips is unavailable on the server.

There is already a ​very capable plugin that adds such support, but it is largely unknown. Moreover, even if it were to be made a Canonical Plugin, most hosts do not (and won't) support libvips until WP itself supports and educates about it. The core functionality from this plugin could be reviewed, tested and added to WP Core.

Benchmark

See attached SPX profile flamegraphs for uploading the attached large image (on a powerful desktop - 8.6s vs 1.5s. Conversely, the client-side media wasm-vips seems to take around 6 seconds to do the same - and you have to wait on the page while that happens.

Responses to potential objections:

  1. "WP 7.1 will have client-side media processing, so server-side media processing is no longer a concern"

This is a fantastic and highly welcome innovation. But it ​only works on Chromium browsers and in the Gutenberg editor - not the Media Upload tool, nor via plugins from the frontend. So, plenty of media uploads will still fall through to the backend.

This effort is complementary to the client-side media effort (which also uses libvips via wasm-vips!).

Also, some sites will surely want to disable the client-side processing, for any number of valid reasons (e.g. battery life, not having to wait for processing to happen before leaving the page)

  1. "Very few hosts have libvips installed. So this wouldn't meet the WP Philosophy threshold of core features need to benefit 80% of users"

There's plenty of historical (and current!) precedent for introducing important features that do not meet this threshold.

Hosts' support for libvips is likely to be lower than these precedents, but this is is an opportunity for outreach and education amongst hosts and users - supporting vips is as simple as something like sudo apt install libvips42 php8.x-ffi.

And, again, this would be a progressive enhancement - if your host doesn't support it, WP falls back to Imagick or GD.

But there is no good reason why this couldn't eventually benefit 100% of WordPress users.

  1. "There would be a maintenance burden associated with it"

WordPress already maintains multiple WP_Image_Editor implementations. A Vips implementation would reuse the existing editor abstraction and would likely share much of its behavior with existing editors. The maintenance surface area appears relatively small relative to the potential performance benefits.

Additionally, there's only been a ​couple of commits per year to the imagick editor.

I and others will surely be willing to help with maintaining this editor.

  1. "There are potential security concerns with FFI"

php-vips ​previously worked via a .so extension, but that was deprecated in favour of the FFI approach.

Some hosts disable FFI, but that is a deployment concern rather than a WordPress compatibility concern. For hosts with security concerns, tools such as ​Snuffleupagus can be used to selectively permit FFI access for libvips while maintaining broader restrictions on FFI usage.

Again, hosts that choose not to enable FFI would continue using Imagick or GD without any change in behavior.

Attachments (3)

vips.png​ (150.8 KB ) - added by nickchomey 5 months ago.
imagick.png​ (108.5 KB ) - added by nickchomey 5 months ago.
testimage.jpg​ (3.4 MB ) - added by nickchomey 5 months ago.

Change History (24)

#1 follow-ups: @swissspidy
5 months ago

  • Severity major → normal

Hosts' support for libvips is likely to be lower than these precedents

I'd recommend adding some detection for it to the update API so that we have some usage stats.

If hosts first need to install libvips, there's no reason why they wouldn't just install that libvips plugin for their customers.

#2 follow-up: @aldavigdis
5 months ago

WordPress is already falling back on GD in case ImageMagick is not found. I see very little wrong with making php-vips the primary option, with ImageMagick becoming the fallback.

It's actually about time as I've been using vips for a while already.

#3 in reply to: ↑ 1 @nickchomey
5 months ago

Replying to swissspidy:

Hosts' support for libvips is likely to be lower than these precedents

I'd recommend adding some detection for it to the update API so that we have some usage stats.

If hosts first need to install libvips, there's no reason why they wouldn't just install that libvips plugin for their customers.

I'm sure many hosts install plugins for users, but I am certain that many site owners absolutely don't want their host meddling with their plugins. This is something that should be built into core and that users don't have to think or even know about. This would also result in better maintenance of the feature.

#4 in reply to: ↑ 2 @nickchomey
5 months ago

Replying to aldavigdis:

WordPress is already falling back on GD in case ImageMagick is not found. I see very little wrong with making php-vips the primary option, with ImageMagick becoming the fallback.

It's actually about time as I've been using vips for a while already.

In what way are you using vips? Via the above-mentioned or another plugin? Some custom code of your own?

#5 @nickchomey
5 months ago

@notglossy fyi, I've proposed merging your plugin into WP Core. Is this something you'd be interested in helping with?

This ticket was mentioned in ​Slack in #hosting by nickchomey. ​View the logs.


5 months ago

#7 in reply to: ↑ 1 @adamsilverstein
5 months ago

Replying to swissspidy:

Hosts' support for libvips is likely to be lower than these precedents

I'd recommend adding some detection for it to the update API so that we have some usage stats.

@swissspidy we may already be able to detect this with the presence of the libvips php package - if not I agree it would be good to add; I have inquired with systems.

#8 follow-up: @nickchomey
5 months ago

To clarify, php-vips just installs with composer and uses the FFI php extension to call the libvips binary directly. We'd probably bundle/vendor it.

I assume that the update api detects the FFI php extension, but would be surprised if it looks for libvips/all binaries in $PATH. It wouldn't be all that hard to add support for though.

Last edited 5 months ago by nickchomey (previous) (diff)

#9 in reply to: ↑ 1 @adamsilverstein
4 months ago

Replying to swissspidy:

Hosts' support for libvips is likely to be lower than these precedents

I'd recommend adding some detection for it to the update API so that we have some usage stats.

If hosts first need to install libvips, there's no reason why they wouldn't just install that libvips plugin for their customers.

cc: @dd32 can we detect the presence of the libvips PHP module in the current telemetry? What level of adoption do you see?

#10 in reply to: ↑ 8 @adamsilverstein
4 months ago

Replying to nickchomey:

To clarify, php-vips just installs with composer and uses the FFI php extension to call the libvips binary directly. We'd probably bundle/vendor it.

@nickchomey

So this wouldn't depend on servers having libvips? We still need libvips, right? Would we bundle the libvips binary for every platform we support? We generally don't ship these types of binaries with core.

Last edited 4 months ago by adamsilverstein (previous) (diff)

#11 follow-up: @adamsilverstein
4 months ago

Worth noting that client-side media leverages libvips as its underlying image processing engine. It also reduces server load and memory usage by moving media processing to the browser.

I posted more about the feature here: ​https://make.wordpress.org/core/2026/07/22/client-side-media-processing-in-wordpress-7-1/

#12 in reply to: ↑ 11 @nickchomey
4 months ago

  • Description modified (diff)

Replying to adamsilverstein:

Replying to nickchomey:

To clarify, php-vips just installs with composer and uses the FFI php extension to call the libvips binary directly. We'd probably bundle/vendor it.

@nickchomey

So this wouldn't depend on servers having libvips? We still need libvips, right? Would we bundle the libvips binary for every platform we support? We generally don't ship these types of binaries with core.

The server would need libvips installed. I was saying we'd vendor the php-vips package so no one has to install that with composer. I assume this is acceptable.

Replying to adamsilverstein:

Worth noting that client-side media leverages libvips as its underlying image processing engine. It also reduces server load and memory usage by moving media processing to the browser.

I posted more about the feature here: ​https://make.wordpress.org/core/2026/07/22/client-side-media-processing-in-wordpress-7-1/

Yes, I addressed this in the first response to potential objections. Plenty of sites/users/devices won't be able or want to use the client side mechanism. (though there was a typo in the title of that objection, which I've just edited. Perhaps why you missed it).

#13 @adamsilverstein
2 months ago

@nickchomey - It turns out we don't collect this information currently. I made an incorrect assumption about libvibs being a php module. Modern php-vips (v2+) is FFI-based, not a PHP extension. So in order to detect this we would need to add additional code to the updater routines as @swissspidy suggested.

If you still want to work on this, a good next step might be proposing adding that data to core's update telemetry (in a separate ticket).

#14 @nickchomey
2 months ago

@adamsilverstein

I'm happy to try to get such data added to Core's update telemetry, but I think it should be considered orthogonal to this proposal, rather than a prerequisite for it.

Again, I expect that such stats would show that a very low percentage of hosts currently have libvips installed, precisely because there's no reason to have it installed when WP does not support its use. So, I worry that this data would be interpreted as evidence against the proposal: "no one supports it, so we shouldn't bother either." But, as described in the OP, there's plenty of precedent for adding APIs etc. with low initial support/usage, which grew over time.

Conversely, if a libvips Image Editor were first added to Core and appropriately announced to hosts and the broader community, I expect support would be added by hosts fairly quickly, given that it is an essentially-free way to significantly reduce the CPU and RAM usage of one of the more hardware-intensive processes they face.

I'd appreciate any guidance on how to proceed with both matters: porting the libvips plugin to Core and adding the relevant telemetry. It would be great to see this make it into 7.2, to complement the excellent work you continue to do on client-side media processing.

#15 @adamsilverstein
2 months ago

I'd appreciate any guidance on how to proceed with both matters: porting the libvips plugin to Core and adding the relevant telemetry. It would be great to see this make it into 7.2, to complement the excellent work you continue to do on client-side media processing.

A PR to add the VIPS editor support to core would be worthwhile to have in place for review and testing.

This ticket was mentioned in ​PR #13762 on ​WordPress/wordpress-develop by ​@nickchomey.


7 weeks ago
#16

  • Keywords has-patch has-unit-tests added

Adds WP_Image_Editor_Vips, an image editor backend backed by
​libvips reached through PHP's FFI extension.

It is listed first in wp_image_editors, ahead of WP_Image_Editor_Imagick and
WP_Image_Editor_GD. It reports itself as unavailable when libvips, the FFI extension, or
ffi.enable is missing, so wp_get_image_editor() falls through to Imagick or GD and
nothing changes on a server that cannot run it.

Trac ticket: https://core.trac.wordpress.org/ticket/65473

Inspired by the ​vips-image-editor-ffi
plugin, but heavily reworked to follow the patterns of the GD and Imagick editors and to
implement equivalent test coverage.

What this adds

  • A complete WP_Image_Editor implementation: load, save, resize, crop, rotate, flip, stream, multi_resize(), and make_subsize().
  • JPEG, PNG, GIF, WebP (including lossless), TIFF, AVIF, HEIC/HEIF and JPEG XL support. Support for each format is probed at runtime by asking libvips to encode a 1×1 image, so a build without the relevant encoder reports the format as unsupported instead of failing on save.
  • Reporting in Site Health and the debug data, alongside the existing Imagick and GD entries, including whether the FFI extension and libvips are available.
  • Local Docker environment support so the test suite can be run against libvips.

Design notes

Several parts of this take a route that is not the obvious one, because the obvious libvips
call does not work. Flagging them here so they do not read as mistakes.

  • EXIF orientation is applied with autorot(), not by rotating and flipping. libvips applies all eight EXIF orientations itself and clears the orientation field as it goes. Using the parent class's rotate/flip switch would leave the field in place, and the saved file would then be oriented a second time when it is loaded again. This is the "EXIF Orientation can be reset afterwards" requirement maybe_exif_rotate() documents.
  • Rotate and flip reset the orientation tag by setting the orientation field to 1 and then calling autorot(). This mirrors Imagick's setImageOrientation( ORIENTATION_TOPLEFT ). Setting the field alone does *not* reach the file: libvips writes JPEG EXIF from the EXIF block rather than from the metadata field. autorot() is the operation that rewrites that block, and declaring the image upright first means it has nothing to apply, so the pixels are untouched and only the tag is corrected. Verified: pixdiff = 0 against the un-reset image, and no change to PNG files that have no EXIF at all.
  • _resize() is a separate method because libvips is immutable — every operation returns a new image — so resize() and make_subsize() both need a fresh image without disturbing $this->image. This is GD's shape rather than Imagick's, which mutates in place and works around it by snapshotting and restoring.
  • Encoder support is probed by writing to a buffer, not a temp file, which avoids a temp file per format check.
  • Paletted PNGs are saved with palette => true. libvips expands a palette on load, so the original colour type is read from the PNG IHDR chunk at load time and a palette is requested back on save. Without it a resized indexed PNG is written as true colour; the same fixture that is 25 KB on disk comes back at 342 KB.
  • image_max_bit_depth is applied as an encoder option, not by downcasting. cast() to a lower band format fails on write with pngsave: invalid buffer size for any 16-bit source (libvips 8.16.1), so the filter is passed to the encoders that accept a bit depth instead.

Vendoring

php-vips is vendored rather than required through Composer, so that a site running this needs
no Composer step and no network access at runtime. The tree is scoped with
​PHP-Scoper into WordPress\VipsDependencies\... with
Jcupitt\Vips deliberately left unscoped, so the public API of the library is unchanged. The
generated autoload.php records the upstream repository, ref and commit it was built from, and
regeneration is deterministic.

tools/php-vips/installer.sh performs the vendoring. With no arguments it resolves the latest
upstream release; --version= and --branch= select a specific ref. It hard-fails if the
scoper step does not actually rewrite files, which it will do silently on PHP 8.5 with older
scoper releases.

Testing instructions

The local Docker environment builds a PHP image with libvips and the FFI extension. Add to
.env (which is not tracked):

LOCAL_PHP_VIPS=true

Then:

npm run env:start

# The editor's own tests.
npm run test:php -- --group wp-image-editor-vips

# The rest of the image surface, which now runs against VIPS.
npm run test:php -- --group image
npm run test:php -- --filter 'Tests_Media|WP_Test_REST_Attachments_Controller'

# The static analysis gates.
npm run env:composer -- lint
npm run typecheck:php -- -- src/wp-includes/class-wp-image-editor-vips.php

To confirm the fallback path, run the same group with FFI disabled. npm run test:php cannot
pass -d through to PHP, so invoke the runner directly:

node ./tools/local-env/scripts/docker.js run -T --rm php php -d ffi.enable=0 ./vendor/bin/phpunit --group image

ffi.enable is what makes it work rather than unloading the extension: the extension stays
loaded, and libvips fails to initialise, so WP_Image_Editor_Vips::test() returns false and
wp_get_image_editor() selects Imagick or GD instead.

Test results

With VIPS enabled:

Suite Result
wp-image-editor-vips 51 tests, 176 assertions, 1 skip, 0 failures
image 343 tests, 901 assertions, 7 skips, 0 failures
Tests_Media + WP_Test_REST_Attachments_Controller 682 tests, 2,583 assertions, 3 skips, 0 failures
wp_generate_attachment_metadata 7 tests, 18 assertions, 0 failures

Static analysis: PHPStan reports no errors on the changed files, and PHPCS is clean.

Without VIPS (the configuration CI runs today), the full suite passes with no failures.

Known limitations

  • image_max_bit_depth has no effect on JPEG, WebP or GIF. libvips stores samples in a fixed set of band formats rather than at an arbitrary bit depth, and only the PNG and HEIF encoders accept a bit depth. Imagick applies the filter to every format because it lowers the depth of the in-memory image. This is documented in get_save_bit_depth().
  • A resized paletted PNG can come out slightly larger than its source. palette => true re-quantises at libvips' default quality, which lands close to the original but can overshoot: of five paletted fixtures, two shrink and three grow by up to a third (test8.png, 45,231 → 60,310 bytes). Passing a Q value makes all five smaller but controls how aggressively colours are reduced, so it trades colour fidelity for bytes. Left alone rather than decided unilaterally.
  • HEIC input depends on the host's encoders for output. Reading works with the standard libheif decoder plugins; writing needs an encoder plugin (for example libx265 for HEIC or aom for AVIF). Support is probed, so a host without them reports the format as unsupported.
  • No CI job runs these tests. The suite runs without libvips in CI, so the editor is not yet exercised automatically. Guidance on how core would like that set up is welcome. On Ubuntu 24.04 the runtime package is libvips42t64 rather than libvips42, and the packaged 8.15.1 is new enough for everything used here, so a stock runner should work without a custom image.

Reviewer notes

  • Two changes outside the new class are not self-explanatory from the diff. The HEIC branch of wp_getimagesize() no longer requires instanceof WP_Image_Editor_Imagick; any editor that claimed HEIC support and loaded the file can report the size, and GD never reaches it because it does not claim HEIC support. Separately, the image_max_bit_depth docblock in the Imagick class stated that the filter "only applies when resizing using the Imagick editor since GD does not support getting or setting bit depth", which stops being true once VIPS honours it.
  • There is an @phpstan-ignore in maybe_exif_rotate(). The is_callable( 'exif_read_data' ) guard is reported as function.alreadyNarrowedType because PHPStan's environment always has the extension, but the extension is optional in practice and @ does not suppress a fatal Call to undefined function. class-wp-image-editor.php:489 carries the identical construct; it is suppressed through a baseline entry, and tests/phpstan/baselines/function.alreadyNarrowedType.neon has the same suppression for the same function in src/wp-admin/includes/image.php. The baselines are documented as being for pre-existing errors and meant to shrink, so an inline ignore was used for new code. Happy to switch to whatever the project prefers.
  • _resize() has no Imagick equivalent. If reviewers prefer the editors to share a shape, this can be dropped in favour of Imagick's snapshot-and-restore approach.
  • The two libvips behaviours in the design notes above (set( 'orientation', 1 ) not reaching the saved file, and cast() breaking pngsave) are the two places where reading the code without context will suggest a simpler implementation. Both were measured, not assumed.

Use of AI Tools

AI assistance: Yes
Tool(s): GitHub Copilot
Model(s): DeepSeek V4.1
Used for: Pair programming - design, code and test implementation. Final implementation and tests were reviewed and edited by me.

#17 @nickchomey
7 weeks ago

@adamsilverstein I've created a PR that should be a pretty good start for implementing this. I endeavoured to cover all the same mechanisms and tests as imagick and gd, provide dockerfiles needed to run it locally etc... As such, it departs somewhat significantly from the plugin that was referenced in the OP.

I didnt add any CI configs/tests, as I'm not really sure how. Seems like something that can come later

I'm open to any feedback that anyone might have!

​@nickchomey commented on ​PR #13762:


7 weeks ago
#18

@notglossy this PR is inspired by your work. Do you have any feedback on it?

​@init0 commented on ​PR #13762:


5 weeks ago
#19

Thanks for working on this! It's great to see libvips being considered for WordPress core. Faster image processing with lower memory usage would be a really useful improvement for WordPress. I maintain a plugin with the same functionality on wordpress.org, ​Indigit Imagination, so I tested revision (​75a5a0f) against problems I had already met. Here are the things I ran into while testing, and I can elaborate on each of them if you want me to. Host: PHP 8.4, libvips 8.16.1, unless noted.

1. Minimum libvips version. ​`WP_Image_Editor_Vips::test()` accepts 8.7. On libvips 8.12.1 (Ubuntu 22.04, PHP 8.1) uploads in PHP-FPM hang with cannot register existing type 'VipsObject', and 4 of the 54 tests in --group wp-image-editor-vips also fail. I recommend 8.13.

2. AVIF is very CPU-heavy. A 33 MP JPEG converted to AVIF takes 42 CPU-seconds with this editor (Imagick: 9.6). With PHP's usual 30 s limit on typical Linux PHP-FPM, the upload is killed after about 5 s, because PHP counts the CPU time of all threads. The ​AVIF save options set no effort, so libvips uses its default of 4. I recommend 3, which took 7.4 CPU-seconds and finished.

3. Files are bigger than Imagick's. JPEG: +25% over the 7 files of one upload, at the same quality setting (82). There are two causes of about equal size. The ​JPEG save options do not optimise the Huffman tables (optimize_coding), and the ​resize call uses libvips' default lanczos3 where ​core's Imagick editor uses a triangle filter (kernel => linear). Fixing either one alone leaves +8% to +9%, and fixing both gives -6.6%. Lanczos is sharper, so it may be deliberate. It still differs from core's current behaviour, so sites that switch will get bigger files than core's Imagick editor gives them today.

4. Metadata. For JPEG and WebP ​the PR strips all metadata from resized images. Core's Imagick editor keeps ​these profiles there: icc, icm, iptc, exif and xmp (colour, copyright, orientation and rights data). Without the colour profile, wide-gamut images may change colour in a browser (expected, I did not measure it). A ​test asserts the stripping, so it may be intended. I recommend matching the metadata semantics of the existing editor. Changing what is kept would be a decision for every editor, not just this one.

5. Damaged files. A PNG cut off at 70% still gets a sub-size built from partial data, where Imagick and GD fail. libvips can make that an error with the loader option fail_on.

6. image_save_progressive. The editor ​does not apply this filter, and ​core's Imagick editor does, for every format it saves. A site that uses it to get progressive images would lose that once this editor comes first in the list. I read this in the code and did not test it. I recommend passing interlace to the save options for JPEG and PNG, and for GIF on libvips 8.14 and newer.

7. Untrusted loaders. libvips chooses a loader from the file's content, and 15 of its loaders are flagged untrusted. Through a normal WordPress upload only BMP reaches one (ImageMagick, the same exposure as in Imagick today). The editor has no loader allowlist: ​`load()` hands any file to libvips. When wp_get_image_editor() is called on a file nobody checked, the editor opened an SVG and a BMP for me, also when they were named .jpg. I recommend setting VIPS_BLOCK_UNTRUSTED=1.

8. No image size limit. A 1.5 MB grey PNG of 40,000 x 40,000 pixels costs 22 CPU-seconds in this editor, and Imagick refused it. Memory stayed low in my test, so this is about CPU only.

Tests. The tests I found missing, most important first:

  • A run on an older libvips. The 4 failures from item 1 only show on an older libvips, so CI needs one.
  • Several requests in one PHP-FPM worker. The hang from item 1 cannot show in a single PHPUnit process.
  • Damaged files. Nothing tests a truncated PNG, GIF or WebP.
  • The metadata policy, which item 4 is about.
  • AVIF encoding. The only AVIF test, ​`test_image_max_bit_depth`, only decodes it, so the CPU cost from item 2 can't show.
  • Rotate and flip. ​Rotate is only checked by size on a square image, so a wrong rotation would still pass. ​Flip is checked at a single pixel, in one direction.

I have more points that are not in this list, and I can explain them if you want. I'm willing to help with this feature, and I can open a pull request against your branch with fixes and tests if you would like that. My plugin also handles each of these points, so it may be useful as a reference.

​@nickchomey commented on ​PR #13762:


5 weeks ago
#20

Thanks for the review! I started addressing all of it yesterday and will probably finish early next week. I'd appreciate another review after that.

​@nickchomey commented on ​PR #13762:


4 weeks ago
#21

@kirsky

Thanks for the detailed review. I've gone through all eight points; most are fixed now, and where I could I measured instead of taking the point on trust. A few I left out on purpose, and there are a couple of your claims I couldn't reproduce and would like your input on. Everything below was measured in Docker with libvips 8.16.1 unless I say otherwise.

What changed

# Point What I did
1 Min libvips version The floor is now 8.13. Below it the editor reports itself unsupported and wp_get_image_editor() falls back to Imagick or GD, so nothing regresses. 8.13 is the first version that can write a palette back to a PNG. I also tried to reproduce the 8.12.1 failure and couldn't; details below.
2 AVIF effort Set to 3, filterable with wp_image_editor_vips_avif_effort. I measured this rather than assumed it, see below.
3a JPEG optimize_coding Set to true. On a 33.8 MP source at Q82: 7,341,179 to 7,002,869 bytes, 4.6% smaller.
3b Resampling kernel Passed explicitly and filterable (wp_image_editor_vips_resampling_kernel). Measured, see below.
4 Metadata stripped on resize strip no longer drops everything. The editor keeps ICC, EXIF, XMP and IPTC, the same set Imagick keeps.
5 Damaged files accepted fail_on => truncated on load for every format except JPEG, which uses none so a damaged JPEG gets filled rather than rejected, matching Imagick.
6 image_save_progressive ignored Applied for JPEG, PNG and GIF. GIF interlace only exists from libvips 8.14, so that one is guarded on the runtime version.
7 Untrusted loaders An allowlist of raster image loaders, plus a format whose loader isn't allowed reporting as unsupported so selection falls through to Imagick.
8 No pixel limit A filterable cap on load, defaulting to 16383² (268,402,689 px). This one fails the image rather than falling back to Imagick, see below.

On the kernel (#3b). I ran a 28-case comparison of linear, lanczos2, lanczos3 and cubic against core's Imagick output, scored with SSIMULACRA2, SSIM, MS-SSIM, IW-SSIM, Butteraugli and CIEDE2000. lanczos3 had the best mean SSIMULACRA2 (7.28, against 1.38 for linear, 5.87 for cubic and 3.20 for Imagick) and led SSIM, MS-SSIM and IW-SSIM as well. It didn't lead everything: lanczos2 was marginally better on mean Butteraugli (7.421 against 7.427), and Imagick was better on mean CIEDE2000 (3.224 against 3.270).

It isn't free either. About 10% more bytes, and on the small images I tested, 10% more wall time. So the default is lanczos3, and if you'd rather have your linear, it's one filter away. I think this is appropriate because maintaining image quality should carry more weight than size and speed - if you turned it into a blurry mess in half the time, that wouldnt be desirable.

On AVIF effort (#2). You were right, and I measured it to be sure. First I confirmed that libvips really does default to effort 4: encoding with no effort option is byte-identical to passing effort = 4. Then, on a 33.8 MP source at Q82:

effort CPU s bytes
0 2.6 9,029,056
2 15.7 6,731,864
3 26.3 6,699,232
4 (default) 72.9 6,676,142
5 105.7 6,700,370

So the default does blow past a 30 s PHP-FPM limit, as you said, though I measured 73 CPU-seconds rather than 42, so the figure depends on the content and the machine. Effort 3 cuts that to 26 s for a 0.35% size cost, and above 4 more effort buys nothing (effort 5 came out slightly larger).

I've kept 3 as the default for now, and there are two things I'd still like your view on. Effort 3 is still only just under 30 s at 33.8 MP, so a larger image can still exceed the limit, and 2 may be the safer choice. And it applies on every AVIF save and stream, not only on a resize.

On truncated files (#5). I couldn't reproduce the PNG case. With libvips 8.16.1 a truncated PNG fails when the pixels are read whether or not fail_on is passed; the decoder raises "end of stream" either way. So fail_on isn't what protects PNG, and WebP behaves the same way. It's what protects GIF and JPEG, which read cleanly without it and fail with it.

That also exposed a weak spot in our own tests. The original test used a PNG, so it passed without the change. It now covers a truncated GIF, which fails if the load options are removed.

If you did see a sub-size produced from a truncated PNG, I'd like the details: the file, its size, and your libvips version. It may be a version difference worth understanding.

On loaders (#7). Confirmed, exactly as you described. An SVG renamed to .jpg is still decoded by svgload. The allowlist handles it.

On metadata (#4). I agree this is a cross-editor policy, and that's how I treated it. The kept set is Imagick's, decided in one place (get_metadata_strategy()), with the keep mask plus compensating removal before libvips 8.16. image_strip_meta still gates it.

I also measured the colour shift you predicted, and it depends on the image. For an sRGB-tagged image, dropping the profile is a no-op in the strict sense: the mean per-channel difference is 0.00, max 0, since interpreting sRGB values as sRGB changes nothing. Our fixture is sRGB-tagged, which is the awkward part. test_resizing_keeps_the_color_profile only proves the ICC_PROFILE segment survives, and it could never catch a colour change. For a genuine wide-gamut image the shift is real: converted to Display P3 and then de-tagged, the mean difference is 2.54 / 3.68 / 0.71 with a maximum of 81 out of 255. So keeping the profile is clearly right, and I'd like to add a wide-gamut fixture so the test actually exercises it.

On the floor and the 8.12.1 failure (#1). I tried to reproduce this one. In ubuntu:22.04 (PHP 8.1.2, libvips 8.12.1-1build1) with php-ffi and php-imagick both loaded, a real load, resize and save succeeded, and Imagick still worked alongside it, with no "cannot register existing type 'VipsObject'" error. So I couldn't reproduce it in a single CLI process. I want to be careful about that, though. You reported it on uploads, which means under PHP-FPM across requests, and a CLI test can't rule that out. The error looks like a per-process GLib type-registration conflict, exactly the kind of thing FPM's lifecycle can expose and a one-shot CLI run may not. If you still have the failing environment, the exact reproduction would be worth having. Either way the floor is above 8.12.1, so that version is excluded regardless.

On the pixel cap (#8). Two corrections to how I first described it, both now fixed in the docblock. It isn't a format limit: a JPEG can describe 65500 pixels per side (verified: libvips encodes 17000- and 40000-pixel-wide JPEGs fine and only fails at 70000). And it isn't a limit the other editors share, since neither GD nor Imagick caps size at all. More importantly, it's a behaviour change rather than a pure guard. _wp_image_editor_choose() selects an editor before opening the file and never retries, and VIPS comes first in the default list, so an over-size image now fails to load where Imagick would have attempted it. I've kept the value you proposed, but if you'd rather it not become a hard failure, that's worth deciding now.

Deliberately left out. You mentioned more points beyond the list. If any of these are among them, I'd rather discuss than have you find them missing:

  • Alpha visibility threshold. Snapping near-transparent pixels to fully transparent changes output pixels, and GD and Imagick have no equivalent step.
  • Preserving animation. Core deliberately flattens animated GIFs into one frame when generating intermediate sizes (wp-includes/media.php), and Imagick selects the first frame to match (setIteratorIndex( 0 )). libvips loads the first frame by default, so this already matches. Preserving animation would move away from core, so it feels like a separate proposal.

Testing that surfaced a real gap: both existing GIF fixtures are single-frame, so the flattening behaviour was untested. There's now a two-frame fixture (tests/phpunit/data/images/gif-animated.gif) and a test asserting the resize and save write exactly one frame back.

Test coverage is up to 77 tests / 243 assertions / 1 skip, and now includes truncated PNG and GIF tests, an AVIF encode test, rotation correctness on non-square pixels, flip on both axes, the min-version gate and the metadata strategy.

I welcome any further feedback on the PR!

Note: See TracTickets for help on using tickets.