A powerful WordPress plugin that optimizes images using imgproxy with Next.js-like features including responsive srcset, priority loading, and DNS prefetch.
- πΌοΈ Automatic Image Optimization: Converts images to modern formats (AVIF, WebP, JPEG, PNG)
- π± Responsive Images: Generates srcset for multiple screen sizes
- β‘ Priority Loading: Detects and preloads critical images
- π Secure URLs: HMAC-signed URLs for security
- π DNS Prefetch: Automatic DNS prefetching for imgproxy domain
- ποΈ Flexible Configuration: Extensive admin settings
- π Multiple URL Formats: Base64 encoded or plain URL formats
- π Source Control: Configurable allowed image sources/domains
- Download or clone this repository
- Upload the
imgproxy-optimizer
folder to your/wp-content/plugins/
directory - Activate the plugin through the 'Plugins' menu in WordPress
- Configure the plugin settings under Settings β Image Optimizer
Navigate to Settings β Image Optimizer in your WordPress admin:
- Imgproxy URL: Your imgproxy server URL (e.g.,
https://imgproxy.example.com
) - Secret Key: Your imgproxy secret key (hex format)
- Secret Salt: Your imgproxy secret salt (hex format)
- Image Quality: Compression quality (1-100, default: 65)
- Image Format: Output format (AVIF, WebP, JPEG, PNG)
- Responsive Widths: Comma-separated widths for srcset generation
- Allowed Image Sources: Domains eligible for optimization
- Use Base64 URL Encoding: Toggle between base64 and plain URL formats
- Enable Image Optimization: Master on/off switch
- HTML Parsing: Scans all
<img>
tags on frontend pages - Source Validation: Checks if images are from allowed sources
- URL Generation: Creates optimized imgproxy URLs with signatures
- Srcset Creation: Generates responsive image sets for different screen sizes
- Priority Detection: Identifies critical images for preloading
https://imgproxy.example.com/signature/rt:fit/w:800/h:0/q:65/f:avif/encoded_url/filename.avif
https://imgproxy.example.com/signature/rt:fit/w:800/h:0/q:65/f:avif/plain/https://example.com/image.jpg
Images are considered priority and preloaded if they have:
fetchpriority="high"
attributeloading="eager"
attribute- CSS classes containing "priority" or "hero"
Control which domains can be optimized:
# Allow specific domains
example.com
cdn.example.com
# Allow wildcard subdomains
*.cloudfront.net
*.amazonaws.com
# Leave empty to allow current site only
This plugin requires an imgproxy server. Here's a basic Docker setup:
docker run -d \
--name imgproxy \
-p 8080:8080 \
-e IMGPROXY_KEY="your_secret_key_here" \
-e IMGPROXY_SALT="your_secret_salt_here" \
-e IMGPROXY_USE_ETAG=true \
-e IMGPROXY_ENABLE_WEBP_DETECTION=true \
-e IMGPROXY_ENABLE_AVIF_DETECTION=true \
darthsim/imgproxy
Generate secure keys for your imgproxy server:
# Generate key
openssl rand -hex 32
# Generate salt
openssl rand -hex 32
Original HTML:
<img src="/uploads/image.jpg" width="800" height="600" alt="Example">
Optimized HTML:
<img src="https://imgproxy.example.com/signature/rt:fit/w:800/h:0/q:65/f:avif/plain/https://example.com/uploads/image.jpg"
width="800"
height="600"
alt="Example"
srcset="https://imgproxy.example.com/.../w:320/... 320w,
https://imgproxy.example.com/.../w:640/... 640w,
https://imgproxy.example.com/.../w:800/... 800w"
sizes="(max-width: 800px) 100vw, 800px"
loading="lazy">
HTML with priority:
<img src="/hero-image.jpg" fetchpriority="high" alt="Hero">
Generated preload link:
<link rel="preload" as="image" href="https://imgproxy.example.com/.../hero-image.jpg">
imgproxy-optimizer/
βββ imgproxy-optimizer.php # Main plugin file
βββ includes/
β βββ class-settings-manager.php # Admin settings page
β βββ class-imgproxy-url-generator.php # URL generation logic
β βββ class-image-processor.php # HTML processing and image handling
βββ README.md # This file
- Output Buffering: Captures and modifies HTML content
- DNS Prefetch: Adds prefetch links in
wp_head
- Settings API: WordPress settings framework integration
- Activation/Deactivation: Proper plugin lifecycle management
- Efficient Parsing: Uses DOMDocument for reliable HTML parsing
- Conditional Processing: Only processes when plugin is enabled and configured
- Smart Caching: Leverages WordPress caching mechanisms
- Minimal Overhead: Lightweight processing with early exits
Invalid Signature Errors:
- Verify secret key and salt are correct
- Ensure URLs with spaces are properly handled
- Check imgproxy server configuration
Images Not Processing:
- Confirm allowed sources configuration
- Verify imgproxy server is accessible
- Check if images are from external domains
Performance Issues:
- Review responsive widths configuration
- Consider disabling for admin pages
- Check imgproxy server capacity
Enable WordPress debug mode to see detailed error messages:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
- WordPress: 5.0+
- PHP: 7.4+
- Imgproxy Server: 2.0+
- Extensions: DOM, OpenSSL
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
GPL v2 or later - see WordPress plugin guidelines
For issues and questions:
- Check the troubleshooting section
- Review imgproxy documentation
- Open an issue on the repository
- Initial release
- Basic imgproxy integration
- Responsive image generation
- Priority loading support
- Admin configuration panel
- Source domain filtering
- Base64/plain URL format options
- Space encoding fix for signatures
Made with β€οΈ for WordPress performance optimization