The Grav Image Color Plugin for Grav CMS introduces grabbing the color palette from an image and Calculating Color Contrast
This plugin introduces grabbing the color palette from an image and Calculating Color Contrast.
The Grav Image Color Plugin for Grav adds the ability to get the dominant color from an image. You can generate a color palette from an image.
The Grav Image Color Plugin is easy to install with GPM.
$ bin/gpm install image-color
Or clone from GitHub and put in the user/plugins/image-color
folder.
For more informations, please check the Installation and update guide.
Twig functions | Parameters | Docs | Return |
---|---|---|---|
{{ GetImageColor() }} |
num_results, reduce_brightness, reduce_gradients,delta |
Return palette | array |
{{ GetContrastYIQ() }} |
hexcolor |
Calculating Color Contrast | string |
Inside templates files.
{{ GetImageColor() }}
without parameters:
{% set color = GetImageColor(page.media['my-image.jpg'].path())[0] %}
{{ color }}
281e3c
{{ GetImageColor() }}
with parameters:
{% set num_results = 10 %}
{% set reduce_brightness = true %}
{% set reduce_gradients = true %}
{% set delta = 10 %}
{% set color = GetImageColor(page.media['my-image.jpg'].path(),num_results, reduce_brightness, reduce_gradients, delta)[0] %}
Number of colors
Default value : 10
Added a filter to reduce brightness variants of the same color.
Default value : true
Added a filter to reduce gradient variants ( useful for logos ).
Default value : true
Allow you to select the quantization delta. The smaller the delta the more accurate the color. This also increases the number of similar colors though.
Default value : 10
{% set num_results = 10 %}
{% set reduce_brightness = true %}
{% set reduce_gradients = true %}
{% set delta = 10 %}
{% set colors = GetImageColor(page.media['my-image.jpg'].path(),num_results, reduce_brightness, reduce_gradients, delta) %}
{% for color in colors %}
<div class="uk-tile uk-tile-default" style="background-color: #{{color}};">
<p class="uk-h4">#{{color}}</p>
</div>
{% endfor %}
{{ GetContrastYIQ(hexcolor) }}
with parameters:
{% set hexcolor = '281e3c' %}
{% set contrast = GetContrastYIQ(hexcolor) %}
{{ GetContrastYIQ }}
light
More info :
six-character hex color
If you find a bug, please open a new issue
I’ve ‘written’ this plugin for my own use. It comes without any guarantee, so your mileage may vary in using it. If you find bugs or have great additions you’d like to share, use github to fork the project and share your improvements by initiating pull request
You can contribute at any time! Before opening any issue, please search for existing issues and review the guidelines for contributing.
After that please note:
See also the list of contributors who participated in this project.
See Licence