GithubHelp home page GithubHelp logo

blue-cookie / kirby-colorextractor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sylvainjule/kirby-colorextractor

0.0 1.0 0.0 144 KB

Extract dominant / average color from any image. Kirby 3 only.

PHP 100.00%

kirby-colorextractor's Introduction

Kirby 3 – Color extractor

colorextractor

This plugins extracts a dominant / average color of any image and stores it in the file's metadata as a HEX value.


Overview

This plugin is completely free and published under the MIT license. However, if you are using it in a commercial project and want to help me keep up with maintenance, please consider making a donation of your choice or purchasing your license(s) through my affiliate link.


1. Installation

Download and copy this repository to /site/plugins/colorextractor

Alternatively, you can install it with composer: composer require sylvainjule/colorextractor


2. Usage

It can be used in two ways :

2.1. Hooks

Once installed within the plugins folder, it will automatically start extracting colors for any image uploaded or replaced in the panel.

2.2. Panel button

If you happen to upload files manually, from frontend or any other way while not trigerring the hooks, custom janitor jobs are also available to catch up with all the images of a website without an associated color.

You'll first need to install the janitor plugin.

Then register the jobs provided by this plugin in your config.php:

'bnomei.janitor.jobs-extends' => [
    'sylvainjule.colorextractor.jobs',
],

You can now use it in your blueprints:

colorextractor:
    type: janitor
    label: Extract missing colors
    progress: 'Processing…'
    job: extractColors

The extractColors job will only extract the missing colors. If you want to force a re-extraction of existing colors, use the forceExtractColors job instead.


3. Options

3.1. Extraction mode

By default, the plugin tends to extract the most dominant / vibrant color of the image. Sometimes though, it can be handy to extract an average one based on an approximation of the whole color palette. When set to average, this options shrinks the image to a 1x1 pixel thumb, then grab the color the image processor chose as the average one. You'll find some examples here.

You can also set it to both, if you want both colors to be extracted and pick from them later from your templates (see the plugin's methods)

Available options are dominant | average | both. Default is dominant.

// config/config.php
return array(
  'sylvainjule.colorextractor.mode' => 'dominant',
);

3.2. Transparency handling

The plugin needs to know how to handle colors with alpha value greater than zero, and what color to fallback to when transparency is detected.

Default is #ffffff

// config/config.php
return array(
  'sylvainjule.colorextractor.fallbackColor' => '#000000',
);

4. Displaying and using the color

4.1. If a single color is extracted

In case you have chosen either dominant (default) or average extraction mode, you can access it directly from your template under the color fieldname:

$image->color();

The plugin works well combined with @hananils's color picker, which might come handy to preview and adjust the detected color.

# Place this inside your file blueprint
fields:
  color:
    type: colors

4.2. If both colors are extracted

If you have chosen to extract and store both colors, the color field will store both HEX values delimited by a comma. The plugin provides a file method to get a specific color from there:

$image->color()->dominantColor();
$image->color()->averageColor();

5. License

MIT


6. Credits

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.