2017 © Pedro Peláez
 

library image-palette

Extracts colors from an image and generates a color palette against a whitelist of colors.

image

brianmcdo/image-palette

Extracts colors from an image and generates a color palette against a whitelist of colors.

  • Sunday, October 25, 2015
  • by brianmcdo
  • Repository
  • 7 Watchers
  • 127 Stars
  • 43,873 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 80 Forks
  • 6 Open issues
  • 5 Versions
  • 17 % Grown

The README.md

ImagePalette

Build Status Total Downloads Latest Stable Version Scrutinizer Code Quality, (*1)

ImagePalette is used to extract a color palette from a given image. Aside from being a native PHP implementation, ImagePalette differs from many palette extractors as it works off a white list color palette. Below is the default palette:, (*2)

, (*3)

The main advantage of working from a color palette is closer matching, as each pixel simply has to calculate the color-distance within the palette and chose the best match. This is useful for working with color taxonomies as the taxonomy should have a finite amount of colors., (*4)

, (*5)

See an example of this in action here: http://alpha.wallhaven.cc/wallpaper/21852, (*6)

Requirements

PHP >= 5.4 php5-gd, (*7)

Installation

Simply add the following to your composer.json file:, (*8)

"require": {
    "brianmcdo/image-palette": "dev-master"
}

Usage

// initiate with image
$palette = new \BrianMcdo\ImagePalette\ImagePalette( 'https://www.google.co.uk/images/srpr/logo3w.png' );

// get the prominent colors
$colors = $palette->colors; // array of Color objects

// to string as json
echo $palette; // '["#ffffdd", ... ]'

// implements IteratorAggregate
foreach ($palette as $color) {
  // Color provides several getters/properties
  echo $color;             // '#ffffdd'
  echo $color->rgbString;  // 'rgb(255,255,221)'
  echo $color->rgbaString; // 'rgba(255,255,221,0.25)'
  echo $color->int;        // 0xffffdd
  echo $color->rgb;        // array(255,255,221)
  echo $color->rgba;       // array(255,255,221,0.25)
  // ...
}

And there we go!, (*9)

Laravel 4

Find the providers key in app/config/app.php and register the ImagePaletteServiceProvider:, (*10)

'providers' => array(
    // ...
    'BrianMcdo\ImagePalette\Laravel\ImagePaletteServiceProvider',
)

Then, find the aliases key in app/config/app.php and register the ImagePaletteFacade:, (*11)

'aliases' => array(
    // ...
    'ImagePalette' => 'BrianMcdo\ImagePalette\Laravel\ImagePaletteFacade',
)

Example:, (*12)

$fileOrUrl = 'https://www.google.com/images/srpr/logo11w.png';

ImagePalette::getColors($fileOrUrl);

Options

Precision

By default, ImagePalette will process every 10th pixel. This is for performance reasons, you can change this like below. The precision is a performance-to-time decision., (*13)

$palette = new \BrianMcdo\ImagePalette\ImagePalette( $src, 5 /* precision */ );

Color Count

To control the amount colors returned set the third parameter. You can also provide the getter with a custom length., (*14)

$palette = new \BrianMcdo\ImagePalette\ImagePalette( $src, 5, 3 /* number of colors to return */ );
$colors = $palette->getColors(7 /* number of colors to return */);

Contribution guidelines

See: https://github.com/brianmcdo/ImagePalette/blob/master/CONTRIBUTING.md, (*15)

The Versions

25/10 2015

dev-master

9999999-dev https://github.com/BrianMcdo/ImagePalette

Extracts colors from an image and generates a color palette against a whitelist of colors.

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • ext-gd *

 

laravel image gd extractor palette color

25/10 2015

v2.0.1

2.0.1.0 https://github.com/BrianMcdo/ImagePalette

Extracts colors from an image and generates a color palette against a whitelist of colors.

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • ext-gd *

 

laravel image gd extractor palette color

08/10 2014

v2.0

2.0.0.0 https://github.com/BrianMcdo/ImagePalette

Extracts colors from an image and generates a color palette against a whitelist of colors.

  Sources   Download

MIT

The Requires

 

laravel image gd extractor palette color

15/02 2014

dev-litespeed

dev-litespeed https://github.com/brianfoxwell/ImagePalette

Extracts colors from an image and generates a color palette against a whitelist of colors.

  Sources   Download

MIT

The Requires

 

laravel image gd extractor palette color

08/01 2014

v1.0

1.0.0.0 https://github.com/brianfoxwell/ImagePalette

Extracts colors from an image and generates a color palette against a whitelist of colors.

  Sources   Download

MIT

The Requires

 

laravel image gd extractor palette color