Utilises the Color Thief PHP library to extract the dominant color from an image.
This can be particularly useful for setting the background color of lazy-loaded images or for styling accompanying HTML markup.
- Silverstripe 4 or 5
- PHP >= 7.2 or >= PHP 8.0
- Supports JPEG, PNG, GIF and WEBP images.
composer require heyday/silverstripe-dominantcolor
Adds the DominantColor()
method to the Image
class which returns the dominant color of an image in hex format #bada55
<div style="background-color: $Image.DominantColor">
Image::get()->find(…)->DominantColor();