AP Image Optimization
Free WordPress plugin: automatic WebP conversion, smart compression, bulk media library optimization, and CDN support — all on your own server, no external APIs.
by Alejandro Perez · github.com/xanderperez7/ap-image-optimization · 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/xanderperez7/ap-image-optimization/archive/refs/heads/main.zipA powerful WordPress plugin that compresses images, converts to WebP, manages custom image sizes, and integrates with your CDN -- all without external dependencies.
Features
- Smart Compression -- Optimizes JPEG, PNG, and GIF images using Imagick (preferred) or GD as a fallback, with a configurable quality slider from 1-100
- Automatic WebP Conversion -- Generates WebP versions of every image and serves them to supported browsers using
<picture>elements with automatic fallback - Bulk Optimization -- Process your entire media library in server-safe batches with a real-time progress bar
- Custom Image Sizes -- Create, edit, and delete custom image dimensions directly from the admin panel without writing code
- Thumbnail Regeneration -- Rebuild all thumbnails including newly added custom sizes, with batch processing to prevent timeouts
- Backup & Restore -- Automatically backs up originals before optimization with one-click restore to revert all changes
- CDN Integration -- Replace your uploads URL with any CDN base URL for faster global delivery
- Lazy Loading -- Adds native
loading="lazy"to images that don't already have it - Stats Dashboard -- Track total space saved and images optimized with persistent statistics that never expire
- Modern Admin UI -- Tabbed interface with toggle switches, toast notifications, status badges, and responsive design
Requirements
- WordPress 5.5 or higher
- PHP 7.4 or higher
- GD library (included with PHP) or Imagick extension (recommended)
Installation
- Download the plugin and extract it
- Upload the
ap-image-optimizationfolder to/wp-content/plugins/ - Activate the plugin through the Plugins menu in WordPress
- Navigate to Settings > Image Optimizer to configure
Configuration
Settings Tab
| Setting | Default | Description |
|---|---|---|
| Optimization Level | 80 | Quality slider from 1 (smallest file) to 100 (best quality). Recommended: 70-85 |
| Auto-Optimize on Upload | Enabled | Automatically compress images the moment they are uploaded |
| Backup Originals | Enabled | Save a copy of every original before optimization |
| WebP Conversion | Enabled | Generate WebP versions alongside the original format |
| CDN URL | Empty | Your CDN base URL (e.g., https://cdn.example.com) to replace the default uploads URL |
Optimize Tab
- Bulk Optimization -- Compresses all images and their thumbnails in your media library
- Regenerate Thumbnails -- Rebuilds every thumbnail using current registered sizes
- Restore Originals -- Reverts all optimized images back to their backed-up originals (available when backups are enabled)
Image Sizes Tab
Create custom image dimensions that WordPress will generate for every uploaded image. After adding or modifying sizes, use Regenerate Thumbnails to apply them to existing images.
Status Tab
View optimization statistics (total space saved, images processed) and system information including:
- Active image processing library (Imagick or GD)
- WebP support availability
- PHP version, memory limit, and max execution time
- Backup status
How It Works
Image Processing
The plugin uses Imagick when available for superior compression quality and metadata stripping. If Imagick is not installed, it falls back to the GD library which ships with PHP. PNG files preserve alpha transparency in both paths.
Batch Processing
Bulk operations automatically calculate a safe batch size based on your server's max_execution_time to prevent timeouts. Each batch is processed via AJAX, allowing the progress bar to update in real time without blocking the browser.
WebP Serving
When WebP conversion is enabled, the plugin:
- Creates a
.webpversion alongside each JPEG and PNG file - Wraps
<img>tags in<picture>elements via thethe_contentfilter - Adds a
<source type="image/webp">for browsers that support it - Preserves the original
<img>tag as a fallback
Backups
Original files are backed up to wp-content/uploads/ap-backups/ with the full directory structure preserved, preventing filename collisions when images in different upload folders share the same name.
Security
- All AJAX endpoints verify a WordPress nonce and check for the
manage_optionscapability - User inputs are sanitized with
sanitize_key(),absint(),esc_url_raw(), andwp_unslash() - All PHP files include an
ABSPATHcheck to prevent direct access - CDN URLs are sanitized with
esc_url_raw()before storage
Frequently Asked Questions
Will this slow down my site? No. The plugin only runs during image uploads (if auto-optimize is enabled) or when you manually trigger bulk operations from the admin panel. On the front end, it applies lightweight content filters for WebP serving and lazy loading.
Can I undo optimization? Yes, as long as Backup Originals is enabled (it is by default). Go to the Optimize tab and click Restore All to revert every image to its original.
Do I need Imagick? No. The plugin works with the GD library that comes built into PHP. However, Imagick produces better quality results at lower file sizes and is recommended if your hosting supports it.
What happens if my server times out during bulk optimization? The plugin automatically adjusts batch sizes based on your server's execution time limit. If a batch fails, the progress is preserved and you can resume by clicking the button again.
Does this work with page builders?
Yes. WebP serving and lazy loading are applied via WordPress's the_content filter, which is compatible with all major page builders.
Changelog
1.0.0
- Initial release
- Image compression with Imagick and GD support
- Automatic WebP conversion and serving
- Custom image size management
- Bulk optimization, thumbnail regeneration, and restore
- CDN URL integration
- Persistent optimization statistics
- Modern tabbed admin interface
License
This plugin is licensed under the GPL-2.0+.