All Projects → ksubileau → Color Thief Php

ksubileau / Color Thief Php

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

Projects that are alternatives of or similar to Color Thief Php

Grafika
An image processing library for PHP
Stars: ✭ 838 (+48.58%)
Mutual labels:  image-processing, gd
Imagegonord
A tool that can convert your rgb images to nordtheme palette
Stars: ✭ 105 (-81.38%)
Mutual labels:  image-processing, color-palette
Smartcrop.php
smartcrop implementation in PHP
Stars: ✭ 37 (-93.44%)
Mutual labels:  image-processing, gd
Php Legofy
Transform your images as if they were made out of LEGO bricks.
Stars: ✭ 161 (-71.45%)
Mutual labels:  image-processing, gd
Simpleimage
A PHP class that makes working with images as simple as possible.
Stars: ✭ 1,184 (+109.93%)
Mutual labels:  image-processing, gd
laravel-color-palette
Laravel Wrapper for @ksubileau/color-thief-php. Grabs the dominant color or a representative color palette from an image. Uses PHP and GD or Imagick.
Stars: ✭ 27 (-95.21%)
Mutual labels:  color-palette, gd
Qgis Earthengine Examples
A collection of 300+ Python examples for using Google Earth Engine in QGIS
Stars: ✭ 482 (-14.54%)
Mutual labels:  image-processing
Tracking With Darkflow
Real-time people Multitracker using YOLO v2 and deep_sort with tensorflow
Stars: ✭ 515 (-8.69%)
Mutual labels:  image-processing
Compressor
An easy to use and well designed image compress library for Android, based on Android native image library. Put forward a framework for quick switch from different compress algorithm.
Stars: ✭ 476 (-15.6%)
Mutual labels:  image-processing
Imageprocessing Labs
computer vision, image processing and machine learning on the web browser or node.
Stars: ✭ 471 (-16.49%)
Mutual labels:  image-processing
Pytorch Cyclegan
A clean and readable Pytorch implementation of CycleGAN
Stars: ✭ 558 (-1.06%)
Mutual labels:  image-processing
Blurry
Blurry is an easy blur library for Android
Stars: ✭ 5,092 (+802.84%)
Mutual labels:  image-processing
Pycnn
Image Processing with Cellular Neural Networks in Python
Stars: ✭ 509 (-9.75%)
Mutual labels:  image-processing
Vapeplot
matplotlib extension for vaporwave aesthetics
Stars: ✭ 483 (-14.36%)
Mutual labels:  color-palette
Jquery Cropper
A jQuery plugin wrapper for Cropper.js.
Stars: ✭ 516 (-8.51%)
Mutual labels:  image-processing
Raisr
A Python implementation of RAISR
Stars: ✭ 480 (-14.89%)
Mutual labels:  image-processing
Srn Deblur
Repository for Scale-recurrent Network for Deep Image Deblurring
Stars: ✭ 537 (-4.79%)
Mutual labels:  image-processing
Gaussianblur
An easy and fast library to apply gaussian blur filter on any images. 🎩
Stars: ✭ 473 (-16.13%)
Mutual labels:  image-processing
Qupath
QuPath - Bioimage analysis & digital pathology
Stars: ✭ 503 (-10.82%)
Mutual labels:  image-processing
Flipsidecamera
The camera app that takes pictures from both sides of your world ! 📷
Stars: ✭ 535 (-5.14%)
Mutual labels:  image-processing

Color Thief PHP

Latest Stable Version Build Status GitHub issues HHVM Packagist License

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

It's a PHP port of the Color Thief Javascript library, using the MMCQ (modified median cut quantization) algorithm from the Leptonica library.

See examples

Requirements

  • PHP >= 5.4 or >= PHP 7.0
  • One or more PHP extensions for image processing:
    • GD >= 2.0
    • Imagick >= 2.0 (but >= 3.0 for CMYK images)
    • Gmagick >= 1.0
  • Supports JPEG, PNG and GIF images.

How to use

Install via Composer

The recommended way to install Color Thief is through Composer:

composer require ksubileau/color-thief-php

Get the dominant color from an image

require_once 'vendor/autoload.php';
use ColorThief\ColorThief;
$dominantColor = ColorThief::getColor($sourceImage);

The $sourceImage variable must contain either the absolute path of the image on the server, a URL to the image, a GD resource containing the image, an Imagick image instance, a Gmagick image instance, or an image in binary string format.

ColorThief::getColor($sourceImage[, $quality=10, $area=null])
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).

You can also pass another additional argument ($area) to specify a rectangular area in the image in order to get dominant colors only inside this area. This argument must be an associative array with the following keys :

  • $area['x'] : The x-coordinate of the top left corner of the area. Default to 0.
  • $area['y'] : The y-coordinate of the top left corner of the area. Default to 0.
  • $area['w'] : The width of the area. Default to the width of the image minus x-coordinate.
  • $area['h'] : The height of the area. Default to the height of the image minus y-coordinate.

Build a color palette from an image

In this example, we build an 8 color palette.

require_once 'vendor/autoload.php';
use ColorThief\ColorThief;
$palette = ColorThief::getPalette($sourceImage, 8);

Again, the $sourceImage variable must contain either the absolute path of the image on the server, a URL to the image, a GD resource containing the image, an Imagick image instance, a Gmagick image instance, or an image in binary string format.

ColorThief::getPalette($sourceImage[, $colorCount=10, $quality=10, $area=null])
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 and $area arguments work 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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].