GithubHelp home page GithubHelp logo

mikkab / color-thief-php Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ksubileau/color-thief-php

0.0 1.0 0.0 128 KB

Grabs the dominant color or a representative color palette from an image. Uses PHP and GD.

color-thief-php's Introduction

#Color Thief PHP

A PHP class for grabbing the color palette from an image. Uses PHP and GD library to make it happen.

It's a PHP port of the [Color Thief Javascript library] (http://github.com/lokesh/color-thief), using the MMCQ (modified median cut quantization) algorithm from the [Leptonica library] (http://www.leptonica.com/).

##How to use

###Get the dominant color from an image

include "color-thief-php/ColorThiefPHP.php";
$dominantColor = ColorThiefPHP::getColor($sourceImage);

The $sourceImage variable must contain either the path (relative or absolute) of the image on the server, or a URL to the image.

ColorThiefPHP::getColor($sourceImage[, $quality=10]) 
returns array(r: num, g: num, b: num)

This function returns an array of three integer values, corresponding to the RGB values (Red, Green & Blue) of the dominant color.

You can pass an additional argument ($quality) to adjust the calculation accuracy of the dominant color. 1 is the highest quality settings, 10 is the default. But be aware that there is a trade-off between quality and speed/memory consumption ! If the quality settings are too high (close to 1) relative to the image size (pixel counts), it may exceed the memory limit set in the PHP configuration (and computation will be slow).

###Build a color palette from an image

In this example, we build an 8 color palette.

include "color-thief-php/ColorThiefPHP.php";
$palette = ColorThiefPHP::getPalette($sourceImage, 8)

Again, the $sourceImage variable must contain either the path (relative or absolute) of the image on the server, or a URL to the image.

ColorThiefPHP::getPalette($sourceImage[, $colorCount=10, $quality=10])
returns array(array(num, num, num), array(num, num, num), ... )

The $colorCount argument determines the size of the palette; the number of colors returned. If not set, it defaults to 10.

The $quality argument works as in the previous function.

##Credits and license

###Author by Kevin Subileau
kevinsubileau.fr

Based on the fabulous work done by Lokesh Dhakar
lokeshdhakar.com
twitter.com/lokesh

###Thanks

  • Lokesh Dhakar - For creating the original project.
  • Nick Rabinowitz - For creating quantize.js.

###License Licensed under the Creative Commons Attribution 2.5 License

  • Free for use in both personal and commercial projects.
  • Attribution requires leaving author name, author homepage link, and the license info intact.

color-thief-php's People

Contributors

ksubileau avatar red-led avatar

Watchers

 avatar

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.