Package Data | |
---|---|
Maintainer Username: | Davide-Gheri |
Maintainer Contact: | davide.gheri@fl-graphics.com (Davide Gheri) |
Package Create Date: | 2016-12-12 |
Package Last Update: | 2016-12-12 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2025-02-09 15:16:01 |
Package Statistics | |
---|---|
Total Downloads: | 66 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 2 |
Total Watchers: | 1 |
Total Forks: | 0 |
Total Open Issues: | 0 |
A package that generates a base64 encoded GIF with the dominant color of the given image (for lazy loading use)
Require the package via composer
composer require ghero/laravel-dominant-color
Include the service provider within your providers in config/app.php
.
'providers' => [
...
Ghero\DominantColor\DominantColorServiceProvider::class,
...
];
Next, add the class alias to the aliases array of config/app.php
.
'aliases' => [
...
'DominantColor' => Ghero\DominantColor\Facades\DominantColor::class,
...
];
Simply call DominantColor::create($file);
passing a valid url to an Image or an Imagick instance
this will generate a string with the base 64 encoded 1x1 GIF
(ex. data:image/gif;base64,R0lGODlhAQABAIABAI2JggAAACwAAAAAAQABAAACAkQBADs=
)
The GIF is only 1 color, the dominant color of the image
You can then easily set this string as src attribute specifing the desired width and height:
<img src='data:image/gif;base64,R0lGODlhAQABAIABAI2JggAAACwAAAAAAQABAAACAkQBADs=' width='200' height='200'/>
You can also get just the hex code of the dominant color using $color = DominantColor::setColor($file)->getColor();
The default output will be a plain hex code without the starting "#".
You can customize the output passing an optional parameter to the getColor
method:
Available outputs:
#FFFFFF
)255,255,255
)['r' => 255, 'g' => 255, 'b' => 255]
)To get the base 64 encoded GIF from an hex code, just use $gif = DominantColor::setGif($color)->getGif()
.