Universal image format converter for Strapi (WebP/AVIF, bulk, quality, fallback)
npm install strapi-plugin-imgfmtconvbash
npm install strapi-plugin-imgfmtconv
`
Or install from GitHub:
`bash
npm install github:A-mi13/imgfmtconv
`
Configuration
The plugin comes with a default config/settings.json file included in the repository. You can edit this file to set up your preferred options before starting Strapi.
$3
| Setting | Type | Default | Description |
|---------|------|---------|-------------|
| enabled | boolean | true | Enable/disable the plugin |
| autoConvert | boolean | true | Auto-convert on file upload |
| qualityWebp | number | 80 | WebP quality (0-100) |
| qualityAvif | number | 70 | AVIF quality (0-100) |
| formatsToConvert | array | ['jpeg', 'png', 'jpg', 'gif'] | Source formats to convert |
| convertTo | array | ['webp', 'avif'] | Target formats |
$3
The default file looks like this:
`json
{
"enabled": true,
"autoConvert": true,
"qualityWebp": 80,
"qualityAvif": 50,
"formatsToConvert": ["jpeg", "png"],
"convertTo": ["webp", "avif"]
}
`
You can edit config/settings.json directly or via the admin panel.
Usage
$3
1. Navigate to Content Manager → Image Format Converter in your Strapi admin panel
2. Configure your settings
3. Use the bulk conversion feature to convert existing images
$3
#### Get Settings
`http
GET /api/imgfmtconv/settings
`
#### Update Settings
`http
PUT /api/imgfmtconv/settings
Content-Type: application/json
{
"enabled": true,
"autoConvert": true,
"qualityWebp": 85,
"qualityAvif": 75,
"formatsToConvert": ["jpeg", "png"],
"convertTo": ["webp"]
}
`
#### Reset to Defaults
`http
POST /api/imgfmtconv/settings/reset
`
#### Reload Settings from File
`http
POST /api/imgfmtconv/settings/reload
`
#### Bulk Convert Existing Images
`http
POST /api/imgfmtconv/bulk-convert
`
How It Works
1. Upload Detection: When a file is uploaded to Strapi, the plugin checks if it matches the configured source formats
2. Conversion: Using Sharp library, the image is converted to the specified target formats
3. Storage: Converted files are saved alongside the original with appropriate extensions
4. Cleanup: When the original file is deleted, converted versions are automatically removed
Performance Benefits
- WebP: 25-35% smaller than JPEG at equivalent quality
- AVIF: 50% smaller than JPEG at equivalent quality
- Automatic format selection: Modern browsers automatically choose the best format
- Fallback support: Original formats are preserved for older browsers
Browser Support
| Format | Chrome | Firefox | Safari | Edge |
|--------|--------|---------|--------|------|
| WebP | 23+ | 65+ | 14+ | 18+ |
| AVIF | 85+ | 93+ | 16.4+ | 85+ |
Requirements
- Node.js >= 18.0.0
- Strapi >= 5.0.0
- Sharp library (automatically installed)
Development
`bash
Clone the repository
git clone https://github.com/A-mi13/imgfmtconv.git
Install dependencies
npm install
Link to your Strapi project
npm link
cd /path/to/your/strapi/project
npm link strapi-plugin-imgfmtconv
`
Contributing
1. Fork the repository
2. Create your feature branch (git checkout -b feature/amazing-feature)
3. Commit your changes (git commit -m 'Add some amazing feature')
4. Push to the branch (git push origin feature/amazing-feature`)