Image Format Converter

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.

  • v1.0.13
  • PHP 8.0+
  • WordPress 6.9 to 7.1
  • GD or Imagick
  • AVIF needs PHP 8.1+

Overview

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, 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.

Zero-PHP Serving

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.

Key Features

Convert on upload

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.

Bulk conversion

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.

HTML rewriting

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.

Originals stay put

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.

Lossless PNG Optimization

Provides opt-in lossless encoding parameters specifically for PNG formats to retain clean typography and alpha transparency, bypassing default lossy WebP parameters.

Size Guard Safeguards

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.

How It Works

Two passes: conversion writes sibling files on upload or in batches, and HTML rewriting serves those paths to browsers that accept them.

Conversion Pipeline

Pipeline A
  1. Upload Trigger

    An image is uploaded through the media library or bulk processor, which invokes the wp_generate_attachment_metadata filter hook.

  2. Environment check

    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.

  3. Backup copy

    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.

  4. Generation & Clamping

    The image is compressed into WebP/AVIF. If the file output size is larger than the original, the converted copy is immediately purged.

HTML Rewrite Pipeline

Pipeline B
  1. WordPress output buffer

    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.

  2. Markup scan

    Image src, srcset, <source>, and CSS url() values are scanned. Sitemaps, feeds, and non-HTML responses are skipped. <a href> is not rewritten.

  3. Disk Existence Audit

    For each matched file URL, the rewriter verifies whether the converted WebP or AVIF asset actually exists on the local disk before rewriting.

  4. Path Rewriting

    URL extensions are swapped, and any responsive descriptors like srcset dimensions are correctly re-appended.

Technical Architecture

Namespace JB_Webdev_Image_Format_Converter. Helpers use the webpavop_ prefix. Settings live in the webpavop_settings option.

Class ComponentRole & Functionality
JB_Webdev_Image_Format_Converter\PluginBootstrap. Registers admin assets, requirement checks, upload conversion, deletion cleanup, and the cron handler.
JB_Webdev_Image_Format_Converter\ConverterEncodes 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\RewriterHooks 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\BulkProcessorAJAX 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\SettingsSettings API for webpavop_settings. Clamps quality, batch size, and the backup folder name, and renders the fields on Tools → Format Converter.
includes/helpers.phpPath 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.

Configuration Settings

Stored in the webpavop_settings option. Quality, batch size, and the backup folder name are clamped on save.

Setting KeyDefaultDescription
quality82WebP lossy quality, from 1 to 100.
avif_enabledfalseAVIF output. Needs PHP 8.1+ with GD 2.3.2+ (imageavif()), or Imagick that lists AVIF.
avif_quality60AVIF lossy quality, from 1 to 100. Used only when AVIF is on.
auto_converttrueConvert new uploads when attachment metadata is generated.
rewrite_enabledtrueRewrite HTML through WordPress's template enhancement buffer and send Vary: Accept.
keep_originalstrueCopy each original into the backup folder after a WebP file is kept. The upload itself is always left in place.
backup_folderwebp-originalsBackup subfolder under uploads. Letters, numbers, and hyphens only.
lossless_pngfalseEncode PNGs as lossless WebP instead of the lossy quality.
skip_if_largertrueDelete a converted file when it is not smaller than the source.
cleanup_on_deletetrueRemove generated WebP, AVIF, and backup files when the attachment is deleted.
convert_jpeg, convert_png, convert_gif, convert_bmptruePer-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_size10How many attachments each bulk-conversion AJAX batch processes.

Server-Level Serving (Zero-PHP Overhead)

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.

Apache Rewrite Rules (.htaccess)

# 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

Nginx Configuration

# 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;
}

Frequently Asked Questions

Does the plugin delete original files when converting?

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.

What happens if a browser does not support WebP or AVIF?

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.

Why did some converted WebP/AVIF files not generate?

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.

Does this plugin work with CDN setups?

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.

How do I verify server-level serving is working?

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.

Changelog

v1.0.13

November 21, 2026

WordPress 6.9 rewriting:

  • HTML rewriting now uses WordPress's template enhancement output buffer. The plugin requires WordPress 6.9.
  • Pages the rewriter handles send Vary: Accept, so a shared cache does not serve WebP or AVIF URLs to a browser that cannot show them.
  • Srcset lookups scan each uploads folder once, instead of once per image.
  • Version and missing-WebP notices show only on the Plugins screen. The missing-AVIF notice shows there and on the settings page. None of them show on the Dashboard.
  • The description now says conversion is lossy at a quality you choose, and that AVIF is off by default.

v1.0.12

November 16, 2026

Stats and AVIF backfill:

  • Space saved counts each image once, using its best variant, so a file with both WebP and AVIF is not counted twice.
  • Turning AVIF on backfills images that were converted before AVIF was enabled. Each image is attempted once.
  • The bulk summary counts skipped images as skipped, not converted. Formats you have switched off are no longer stuck as pending.
  • A backup copy is written only when the WebP file is kept.
  • Fixed a PHP 8.5 imagedestroy() deprecation during GD conversion.

v1.0.11

August 17, 2026

Serving and rewriter fixes:

  • Nginx tries AVIF, then WebP, then the original, instead of one suffix that could skip WebP.
  • Srcset parsing keeps URLs that contain commas. <source> type attributes stay in sync, and <a href> links are not rewritten.
  • The rewriter skips XML payloads, treats Accept quality 0 as unsupported, and does not buffer sitemap URLs.
  • Bulk conversion separates the in-flight lock from the running heartbeat so Stop and Reset do not race.
  • The backup folder name rejects path traversal. Uninstall removes size-saved meta, cron hooks, and transients.

v1.0.10

July 13, 2026

Rename:

  • Plugin name is JBWEBDEV Image Format Converter. Text domain jbwebdev-image-format-converter. Internal prefixes are WEBPAVOP_ and webpavop_.
  • Start Bulk Conversion hides when nothing is left to convert.

v1.0.9

June 27, 2026

Added & Fixed:

  • Fixed WordPress admin panel notices (such as third-party license nags) disrupting the layout of the plugin's settings panel.
  • Fixed conversion failures on palette-based index source images (PNG-8 formats and GIFs) by promoting index palettes to truecolor inside the GD conversion module.
  • Added detailed error logs gated behind WP_DEBUG_LOG that write GD/Imagick exception errors to simplify debugging conversion failures.
  • Updated system requirements checks to confirm WordPress 7.0 compatibility.

v1.0.8

June 26, 2026

Refined HTML Rewriting:

  • Hardened the srcset parser to correctly loop through and rewrite every comma-separated candidate url.
  • Added defensive descriptor mappings. If an element lacks a width descriptor, the plugin attempts to parse and extract dimensions directly from the file name suffix (e.g. -600x400.jpg to 600w).
  • Added limits to responsive size candidates. Image generation size is capped relative to the maximum declared tag dimensions, saving significant CPU overhead and disk space.

v1.0.7

June 20, 2026

AVIF support intro:

  • Introduced full AVIF format support with options to enable AVIF and adjust AVIF compression quality in settings.
  • Added a bulk-reset action so a stuck run can be cleared without editing the database. The running flag refreshes on every batch.
  • Added safeguards to check for empty/zero-byte outputs during conversion to prevent saving corrupted assets.
  • Added response filters to ensure sitemaps, JSON responses, and non-HTML assets are ignored by the HTML output rewriter.