WebP, and AVIF when you want it
WebP is lossy at quality 82 by default (1–100). AVIF is off until you enable it, then lossy at quality 60. PNGs can use lossless WebP instead. A converted file is kept only when it is smaller than the original.
Convert JPEG, PNG, GIF, and BMP uploads to WebP, and to AVIF when you turn it on. Rewrite page HTML through WordPress 6.9, or serve the files from Apache or Nginx with no PHP in the request.
JBWEBDEV Image Format Converter converts media-library images to WebP, and to AVIF when you enable it, using WordPress's own GD or Imagick libraries. Nothing leaves the server: no account, no API key, and no CDN required. Open it at Tools → Format Converter. WebP quality defaults to 82. AVIF stays off until the server can encode it (PHP 8.1+ with GD 2.3.2+, or Imagick with AVIF). Staging a site first? EZ Page Sync moves the content over before this plugin converts the media.
WebP is lossy at quality 82 by default (1–100). AVIF is off until you enable it, then lossy at quality 60. PNGs can use lossless WebP instead. A converted file is kept only when it is smaller than the original.
Avoid PHP overhead entirely. By injecting custom server configuration rules, Apache and Nginx serve WebP/AVIF versions directly when client compatibility and local asset exists.
JPEG, PNG, GIF, and BMP uploads are converted with the attachment, including intermediate sizes. Each format can be switched off. Animated GIFs are left alone.
Convert the existing library in AJAX batches (10 images by default). Start, Stop, and Reset are on the settings page, with a progress bar and a converted / skipped / failed summary. Turning AVIF on later backfills images that were already converted to WebP.
Uses WordPress 6.9's template enhancement output buffer, not its own buffer. It rewrites <img> src, <source>, and CSS url() values, including srcset, when the browser accepts AVIF or WebP and the file is on disk. Anchor href links are left alone. Eligible pages send Vary: Accept.
The file in the uploads folder is never replaced. Keep originals (on by default) copies it into webp-originals/ only after a WebP file is kept. Cleanup on delete removes the generated files and that backup when the attachment is deleted.
Provides opt-in lossless encoding parameters specifically for PNG formats to retain clean typography and alpha transparency, bypassing default lossy WebP parameters.
Compares files defensively. If the resulting WebP or AVIF output is larger than the original source file, the duplicate is purged, preventing waste of disk space.
Two passes: conversion writes sibling files on upload or in batches, and HTML rewriting serves those paths to browsers that accept them.
An image is uploaded through the media library or bulk processor, which invokes the wp_generate_attachment_metadata filter hook.
WebP tries WP_Image_Editor, then GD, then Imagick. AVIF tries GD (imageavif(), PHP 8.1+), then Imagick. AVIF runs only when you have enabled it.
Originals stay in the uploads folder. If Keep originals is on, a copy is written to the backup folder only after the WebP file is kept.
The image is compressed into WebP/AVIF. If the file output size is larger than the original, the converted copy is immediately purged.
On template_redirect the rewriter attaches to wp_template_enhancement_output_buffer, WordPress 6.9's buffer. It only does that when the browser accepts AVIF or WebP. Vary: Accept is added on wp_headers for eligible HTML pages either way.
Image src, srcset, <source>, and CSS url() values are scanned. Sitemaps, feeds, and non-HTML responses are skipped. <a href> is not rewritten.
For each matched file URL, the rewriter verifies whether the converted WebP or AVIF asset actually exists on the local disk before rewriting.
URL extensions are swapped, and any responsive descriptors like srcset dimensions are correctly re-appended.
Namespace JB_Webdev_Image_Format_Converter. Helpers use the webpavop_ prefix. Settings live in the webpavop_settings option.
| Class Component | Role & Functionality |
|---|---|
JB_Webdev_Image_Format_Converter\Plugin | Bootstrap. Registers admin assets, requirement checks, upload conversion, deletion cleanup, and the cron handler. |
JB_Webdev_Image_Format_Converter\Converter | Encodes WebP and AVIF, writes the backup copy after a WebP is kept, drops a file that is not smaller than the source, and stores the bytes saved. |
JB_Webdev_Image_Format_Converter\Rewriter | Hooks wp_headers for Vary: Accept and wp_template_enhancement_output_buffer for HTML. Also builds the Apache and Nginx snippets and can write the Apache block into .htaccess. |
JB_Webdev_Image_Format_Converter\BulkProcessor | AJAX batches with a separate in-flight lock and a running heartbeat. Stop finishes the current batch. Reset clears a stuck run. Pending counts follow the formats you have switched on, and include AVIF backfill when AVIF is catching up. |
JB_Webdev_Image_Format_Converter\Settings | Settings API for webpavop_settings. Clamps quality, batch size, and the backup folder name, and renders the fields on Tools → Format Converter. |
includes/helpers.php | Path helpers (webpavop_get_webp_path(), webpavop_get_avif_path()), upload-directory checks, animated-GIF detection, and the cached conversion stats. Space saved counts each image once, using its best variant. |
Stored in the webpavop_settings option. Quality, batch size, and the backup folder name are clamped on save.
| Setting Key | Default | Description |
|---|---|---|
quality | 82 | WebP lossy quality, from 1 to 100. |
avif_enabled | false | AVIF output. Needs PHP 8.1+ with GD 2.3.2+ (imageavif()), or Imagick that lists AVIF. |
avif_quality | 60 | AVIF lossy quality, from 1 to 100. Used only when AVIF is on. |
auto_convert | true | Convert new uploads when attachment metadata is generated. |
rewrite_enabled | true | Rewrite HTML through WordPress's template enhancement buffer and send Vary: Accept. |
keep_originals | true | Copy each original into the backup folder after a WebP file is kept. The upload itself is always left in place. |
backup_folder | webp-originals | Backup subfolder under uploads. Letters, numbers, and hyphens only. |
lossless_png | false | Encode PNGs as lossless WebP instead of the lossy quality. |
skip_if_larger | true | Delete a converted file when it is not smaller than the source. |
cleanup_on_delete | true | Remove generated WebP, AVIF, and backup files when the attachment is deleted. |
convert_jpeg, convert_png, convert_gif, convert_bmp | true | Per-format switches. A format set to false is neither converted nor counted as pending. |
cdn_url | '' | Optional CDN base URL. Treated as a mirror of the uploads tree so rewritten URLs still map to local files. |
batch_size | 10 | How many attachments each bulk-conversion AJAX batch processes. |
HTML rewriting uses WordPress's output buffer, which is fine for most sites. For image requests themselves, Apache or Nginx can answer without PHP. A request for image.png stays on that URL. If the browser accepts AVIF or WebP and the sibling file exists, the server sends that file and sets Vary: Accept. Paste these from Tools → Format Converter, or use Apply to .htaccess for the Apache block. The marker name is JBWEBDEV Image Format Converter.
# BEGIN JBWEBDEV Image Format Converter
<IfModule mod_rewrite.c>
RewriteEngine On
# Serve AVIF first (best compression) if browser supports it and an .avif file exists.
RewriteCond %{HTTP_ACCEPT} image/avif
RewriteCond %{REQUEST_FILENAME} ^(.+)\.(jpe?g|png|gif|bmp)$
RewriteCond %1.avif -f
RewriteRule ^(.+)\.(jpe?g|png|gif|bmp)$ $1.avif [T=image/avif,E=WEBPAVOP_AVIF:1,L]
# Fall back to WebP if browser supports it and a .webp file exists.
RewriteCond %{HTTP_ACCEPT} image/webp
RewriteCond %{REQUEST_FILENAME} ^(.+)\.(jpe?g|png|gif|bmp)$
RewriteCond %1.webp -f
RewriteRule ^(.+)\.(jpe?g|png|gif|bmp)$ $1.webp [T=image/webp,E=WEBPAVOP_WEBP:1,L]
</IfModule>
<IfModule mod_headers.c>
# Unconditionally vary Accept for all matching image types to ensure correct CDN/proxy caching
SetEnvIf Request_URI "\.(?:jpe?g|png|gif|bmp)$" WEBPAVOP_IMAGE
Header merge Vary Accept env=WEBPAVOP_IMAGE
</IfModule>
<IfModule mod_mime.c>
AddType image/webp .webp
AddType image/avif .avif
</IfModule>
# END JBWEBDEV Image Format Converter# JBWEBDEV Image Format Converter — Nginx config snippet
# Add this inside your WordPress server {} block:
# WARNING: Adding add_header inside a location block in Nginx prevents inheritance
# of global server-level headers (e.g. X-Frame-Options, Content-Security-Policy).
# If you use these headers, you must re-declare them inside this location block.
# NOTE: Also add "image/avif avif;" to your mime.types file (or an include block) if
# Nginx does not already serve AVIF with the correct Content-Type header.
map $http_accept $avif_suffix {
default "";
"~*image/avif" ".avif";
}
map $http_accept $webp_suffix {
default "";
"~*image/webp" ".webp";
}
location ~* ^(.+)\.(jpe?g|png|gif|bmp)$ {
add_header Vary Accept;
# Re-declare global headers here if needed, for example:
# add_header X-Frame-Options "SAMEORIGIN";
# Dual-Accept clients try AVIF then WebP then the original (Apache does this too).
try_files $1$avif_suffix $1$webp_suffix $uri =404;
expires 365d;
}No. Originals stay in the uploads folder so browsers that cannot use WebP or AVIF still get them. With Keep originals on (the default), the plugin also copies each original into /wp-content/uploads/webp-originals/ after a WebP file is kept. A backup is not written when conversion fails or the WebP is discarded for being larger. Cleanup on delete, also on by default, removes the generated WebP, AVIF, and backup files when you delete the attachment.
The rewriter only swaps image URLs when the Accept header asks for AVIF or WebP. A quality of 0 counts as unsupported. Other browsers keep the original JPEG, PNG, GIF, or BMP URLs. Pages the rewriter handles also send Vary: Accept, so a shared cache does not hand a modern-format page to an older browser.
If the converted file is not smaller than the original, the plugin deletes it and keeps the source. Animated GIFs are skipped, and a zero-byte encoder result is treated as a failure. You can also switch JPEG, PNG, GIF, or BMP off individually. AVIF is off until you enable it, and it only encodes when the server can: PHP 8.1+ with GD 2.3.2+ (imageavif()), or Imagick that lists AVIF.
Yes. Set a CDN URL under Tools → Format Converter. The rewriter matches image URLs on that host and points them at the .webp or .avif files, as long as those files exist where the CDN can serve them. No account or external API is required.
Turn off HTML rewriting, then request an image. The URL still ends in .jpg (or png, gif, bmp), but the Network tab shows Content-Type: image/webp or image/avif when the browser accepts that format and the file is on disk. The Apache rules also send Vary: Accept on those image requests.
WordPress 6.9 rewriting:
Vary: Accept, so a shared cache does not serve WebP or AVIF URLs to a browser that cannot show them.Stats and AVIF backfill:
imagedestroy() deprecation during GD conversion.Serving and rewriter fixes:
<source> type attributes stay in sync, and <a href> links are not rewritten.Accept quality 0 as unsupported, and does not buffer sitemap URLs.Rename:
jbwebdev-image-format-converter. Internal prefixes are WEBPAVOP_ and webpavop_.Added & Fixed:
WP_DEBUG_LOG that write GD/Imagick exception errors to simplify debugging conversion failures.Refined HTML Rewriting:
srcset parser to correctly loop through and rewrite every comma-separated candidate url.-600x400.jpg to 600w).AVIF support intro: