FaB Boost for Images is a lightweight, efficient image processing microservice designed to simplify remote image hosting for client sites. It provides a straightforward, URL-based API for hassle-free image transformations.
- On-the-fly image processing
- Secure domain whitelisting
- Image caching
- Support for multiple image formats (JPG, PNG, GIF, BMP, WebP, AVIF)
- Configurable image manipulations
- Cache-Control headers for optimal performance
- File size and dimension limits for security
- PHP 7.4
- Composer
- Required PHP extensions:
- GD or ImageMagick
- curl
- fileinfo
- Composer packages:
- league/glide
- nyholm/psr7
- laminas/laminas-httphandlerrunner
- Clone the repository:
git clone https://github.com/sleggat/fab-boost-for-images.git
- Install dependencies:
composer install
- Create required directories:
mkdir cache_local cache_remote
chmod 777 cache_local cache_remote
- Configure your web server (example Nginx configuration included)
- Update the
$whitelistedDomains
array inimage.php
to include your allowed domains:
$whitelistedDomains = [
'your-domain.com',
'otherdomain.com'
];
- Adjust size limits if needed:
$maxFileSize = 10 * 1024 * 1024; // 10MB default
// Maximum dimensions
if ((isset($glideParams['w']) && $glideParams['w'] > 5000)...
The service accepts URLs in the following format:
https://your-domain.com/image/example.com/path/to/image.jpg
Add image manipulation parameters as query strings:
w
: Widthh
: Heightq
: Quality (0-100)blur
: Blur effectsharp
: Sharpeningfm
: Format conversioncrop
: Crop modebri
: Brightnesscon
: Contrastgam
: Gammaflip
: Flip imageor
: Orientationbg
: Background colour
Example:
https://your-domain.com/image/example.com/image.jpg?w=800&h=600&q=80
The service currently includes several security measures:
- Domain whitelisting
- File size limits (10MB default)
- Dimension limits (5000px default)
- File type verification
- Input sanitization
- Secure file handling
Images are cached in two layers:
- Original downloaded images in the
cache_remote/
directory - Processed images in the
cache_local/
directory
- This is a fairly new project and I wouldn't recommend using this in production, yet.
- You might want to implement more rigorous checks or disable CPU intensive processes like blur.
Contact me at [email protected] https://frontandback.co.nz