Download the PHP package enjoydev/bolt-webp without Composer
On this page you can find all versions of the php package enjoydev/bolt-webp. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package bolt-webp
Bolt WebP Converter
A Bolt CMS extension that automatically converts images to WebP format with customizable thumbnails, fit modes, and quality settings.
Features
- 🚀 Direct conversion – Converts original images directly to WebP (no intermediate compression artifacts)
- 📐 All fit modes – Supports
crop,contain,max,fill, andstretchmodes - 🔍 Smart sizing – Handles width/height parameters intelligently (single dimension, both, or none)
- 🎨 Transparency support – Preserves alpha channels for PNG and GIF images
- 📁 Custom paths – Define your own output directories
- ⚡ Caching – Generates WebP files only once, reuses them on subsequent requests
- 📊 Object Interface – Returns a rich object with path, dimensions, and Alt text (v1.0.1+)
- 🛡️ Graceful fallback – Returns original image path if conversion fails
Requirements
- PHP 8.0 or higher
- Bolt CMS 6.0
- GD extension with WebP support
Installation
1. Install via Composer
2. Clear the cache
After installation, clear the cache to register the new Twig filter:
3. Verify installation
Ensure the extension is loaded:
You should see EnjoyDev\BoltWebp\Extension in the list.
Configuration
This extension works out of the box with sensible defaults. No configuration file is required. If you need to adjust quality or default paths, you can do so directly in your Twig templates.
Usage
The webp_thumbnail filter returns a WebPImage object. This object contains the path, dimensions, and metadata, but can be used as a string for backward compatibility.
Basic Usage
Accessing Dimensions & Metadata (v1.0.1+)
Because the filter returns an object, you can easily access the width, height, and Alt text of the generated WebP image.
Fit Modes
| Mode | Parameter | Description |
|---|---|---|
| Max (default) | 'm' or 'max' |
Fits within bounds without upscaling smaller images |
| Crop | 'c' |
Resizes to fill dimensions and crops excess data |
| Contain | 'n' or 'contain' |
Fits image within bounds, maintains aspect ratio |
| Fill | 'f' or 'fill' |
Fits within bounds, fills empty space with white background |
| Stretch | 's' or 'stretch' |
Stretches exactly to dimensions (distorts image) |
Single Dimension
If you specify only one dimension, the other will be calculated automatically to maintain aspect ratio:
Custom Output Directory
You can specify a custom directory for the WebP files:
Responsive Images (Picture Element)
This is the recommended way to use WebP for better performance. You can still use the object directly in srcset.
Advanced Example (Multiple Sizes)
How It Works
- Extract image – Gets the image path from Bolt field types (
ImageField,Image,FieldTranslation) - Calculate dimensions – Processes width/height parameters and fit mode
- Generate filename – Creates unique filename with hash based on parameters
- Check cache – Returns existing WebP file if it exists
- Convert – Converts original image directly to WebP using GD library
- Save – Stores WebP file in the public directory (usually
public/thumbs) - Return Object – Returns
WebPImageobject containing path, width, height, and alt text
File Naming Convention
The extension generates filenames in this format:
Where hash is an 8-character MD5 hash based on dimensions, fit mode, quality, and original filename.
Example:
- Original:
soup.png - Output:
soup-a1b2c3d4.webp
Maintenance
WebP files are generated once and stored permanently on your server. If you frequently update images or change dimensions, you might want to clean up old files.
Cleaning up old files
You can remove unused WebP files by deleting the contents of the public/thumbs directory (or your custom directories) via FTP or a command line tool.
Example command to remove all generated thumbnails:
Note: Be careful not to delete folders that contain manually uploaded files if you use overlapping paths.
Troubleshooting
WebP files not being generated
Ensure GD is installed with WebP support:
You should see WebP Support => enabled.
Allowed memory size exhausted
If you are processing very large images (e.g., 4000px+), PHP might run out of memory. Increase the memory limit in your php.ini:
Or temporarily in your script (not recommended for production):
Permission issues
Ensure the web server has write permissions to the output directories (usually public/thumbs):
Images not showing up
Check the Bolt logs for conversion errors:
Support
Found a bug or have a feature request? Please report it on the GitHub issue tracker.
- 🐛 Report a bug: Create an Issue
- 💡 Feature request: Create an Issue
- 📖 Bolt Documentation: docs.boltcms.io
License
This extension is released under the MIT License.
Credits
Developed by EnjoyDev for the Bolt CMS community.