PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Sazan Dauti  >  PHP Color Picker  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: This is an example of how PHP Color Extractor can be used
Class: PHP Color Picker
Extract the main colors of a given image file
Author: By
Last change:
Date: 8 years ago
Size: 1,086 bytes


Class file image Download

//Require the ColorExtractor Class

$img = "";

$ce = new ColorExtractor;

Call the function getColors, this function gets the main colors from the image
getColors(Link to Image, Number of colors to return, minumum difference between each color, Type of return "rgb" or "hex");
$colorArray = $ce->getColors($img, 5, 11, "rgb");


<img src="<?php echo $img; ?>" height="200px">

<br /><br />

<table width="200px" border="1">

foreach ($colorArray as $color) {
    if (
substr($color, 0, 1) == "#") {
'<td width="50%" align="center">' . $color . '</td><td width="50%" align="center"><div style="background-color:' . $color . '; width:50px; height:50px;"></div></td>';
    } else {
'<td width="50%" align="center">' . $color . '</td><td width="50%" align="center"><div style="background-color:rgb(' . $color . '); width:50px; height:50px;"></div></td>';