This plugin introduces grabbing the color palette from an image and Calculating Color Contrast.
- Grav Image Color Plugin
- Installation and Updates
- Twig Functions
- Usage
- Troubleshooting
- Disclaimer
- Tested on Grav
- Contributing
- Licence
- Thanks
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.
{% set color = GetImageColor(page.media['my-image.jpg'].path())[0] %}
281e3c
{% 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 %}
{% set hexcolor = '281e3c' %}
{% set contrast = GetContrastYIQ(hexcolor) %}
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:
- If you find a bug, would like to make a feature request or suggest an improvement, please open a new issue. If you have any interesting ideas for additions to the syntax please do suggest them as well!
- Feature requests are more likely to get attention if you include a clearly described use case.
- If you wish to submit a pull request, please make again sure that your request match the guidelines for contributing and that you keep track of adding unit tests for any new or changed functionality.
See also the list of contributors who participated in this project.
See Licence