WP WebP Intervention Converter
Converts JPG/PNG images to WebP format using Intervention Image v3 with file size optimization.
by Nguyên Khôi · github.com/nguyenkhoi489/wp-webp-intervention-converter · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/nguyenkhoi489/wp-webp-intervention-converter/archive/refs/heads/master.zipReadme
WP WebP Intervention Converter
A complete WordPress plugin that converts JPG/PNG images to WebP format using Intervention Image v3, with automatic file size optimization.
Features
- ✅ Auto Convert on Upload: Automatically converts images to WebP when uploaded to Media Library
- ✅ File Size Optimization: Intelligent algorithm reduces quality and/or resizes images to meet file size limits
- ✅ Batch Conversion: Convert all existing images with progress tracking
- ✅ Frontend URL Replacement: Automatically serves WebP versions on frontend while preserving originals
- ✅ Configurable Settings: Control quality, file size limits, and enable/disable auto-conversion
- ✅ PHP 8.1+ Compatible: Modern, object-oriented code
Installation
-
Upload the plugin to
/wp-content/plugins/wp-webp-intervention-converter/ -
Install Intervention Image v3 via Composer:
cd wp-content/plugins/wp-webp-intervention-converter composer require intervention/image -
Activate the plugin through the 'Plugins' menu in WordPress
-
Configure settings at 'WebP Converter' menu in WordPress admin
Requirements
- PHP 8.1 or higher
- WordPress 5.0 or higher
- GD or Imagick PHP extension
- Composer (for installing dependencies)
Usage
Settings
Navigate to WebP Converter in WordPress admin to configure:
- Enable Auto Convert: Toggle automatic conversion on image upload
- Default Quality: Set WebP quality (40-100, default: 80)
- Max File Size Limit (KB): Maximum allowed WebP file size (default: 200KB)
Auto Conversion
When auto-convert is enabled, newly uploaded JPG/PNG images are automatically converted to WebP format. The plugin will:
- Convert the image to WebP at the configured quality
- Check if file size is under the limit
- If over limit, automatically reduce quality or resize until it fits
Batch Conversion
To convert all existing images:
- Go to WebP Converter settings page
- Scroll to "Batch Convert Existing Images"
- Click Start Batch Conversion
- Watch the progress bar as images are processed sequentially
Frontend Display
The plugin automatically replaces image URLs on the frontend:
- Original JPG/PNG files are NOT deleted
- WebP versions are served when available
- Browsers that don't support WebP will fall back to originals
- Works with
the_content,wp_get_attachment_url, andwp_get_attachment_image_srcfilters
File Size Optimization Algorithm
The plugin uses an intelligent optimization algorithm to ensure WebP files stay under the configured size limit:
- Start with default quality (e.g., 80)
- Convert and save as WebP
- Check file size:
- ✅ If under limit → Done!
- ❌ If over limit → Continue
- Reduce quality by 5 (80 → 75 → 70...)
- If quality reaches minimum (40) and still too large:
- Resize dimensions by 10% (width × 0.9, height × 0.9)
- Reset quality to default
- Repeat optimization
- Continue until file size is under limit or dimensions are too small
File Structure
wp-webp-intervention-converter/
├── wp-webp-intervention-converter.php # Main plugin file
├── composer.json # Intervention Image dependency
├── includes/
│ ├── class-webp-converter.php # Conversion logic
│ └── class-webp-settings.php # Settings page
├── assets/
│ ├── js/
│ │ └── batch-convert.js # AJAX batch processing
│ └── css/
│ └── admin-style.css # Admin styling
└── README.md # This file
Technical Details
Intervention Image v3
This plugin uses Intervention Image v3 for all image manipulations. It's a modern, powerful PHP image handling library.
WordPress Hooks Used
wp_generate_attachment_metadata: Auto-convert on uploadthe_content: Replace URLs in post contentwp_get_attachment_url: Replace attachment URLswp_get_attachment_image_src: Replace image source arrays- AJAX actions:
get_images_for_batch,batch_convert_image
Security
- Nonce verification for all AJAX requests
- Capability checks (
manage_options) - Sanitized input/output
- Escaped HTML output
Support
For issues or feature requests, please contact the plugin author.
License
GPL v2 or later
Changelog
1.0.0
- Initial release
- Auto convert on upload
- Batch conversion with progress bar
- File size optimization
- Frontend URL replacement