mirror of
https://github.com/ivuorinen/palette.git
synced 2026-01-30 00:43:42 +00:00
.gitignore:
- Added vendor folder
composer.json:
- Added required description
- Fixed autoloader classmap
- Removed extra-section
example.php:
- Now has working autoloader and non-autoloader examples
- Better wording in comments and caching example, also includes destination configuration example
Palette.php:
- Added MIT license block and changed the license links from GPL2 to MIT to reflect composer.json file
- Moved file from from a directory to a better one, reflecting class namespace.
- Combined tests to fewer try {} catch {} -blocks
- Added comments to help understand the code
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
error_reporting(E_ALL);
|
||||
require '../palette.php';
|
||||
// require_once '../src/ivuorinen/Palette/Palette.php'; /* If we are not using Composer autoloader */
|
||||
require_once '../vendor/autoload.php'; /* We are using Composer autoloader (run composer install in project root) */
|
||||
|
||||
|
||||
$testimages_full_process = array(
|
||||
'example.gif',
|
||||
@@ -35,12 +37,34 @@ foreach ($testimages_controlled_process as $image) {
|
||||
$test->precision = 10; // Bigger is faster, smaller returns more colors
|
||||
$test->returnColors = 5; // How many colors we want in our array at most
|
||||
|
||||
// Get the colors as an array
|
||||
$colors = $test->getPalette();
|
||||
// Configure your destination file name fully we get
|
||||
// an array encoded to json, so .json extension is good choice
|
||||
$test->destination = dirname(__FILE__) . '/' . md5($test->filename) . '.json';
|
||||
|
||||
echo "<pre>"
|
||||
. "Processing {$test->filename}\n"
|
||||
. print_r($colors, true)
|
||||
. "Processing {$test->filename}\n";
|
||||
|
||||
if (is_readable($test->destination)) {
|
||||
|
||||
echo "Returning data from cache: {$test->destination}\n";
|
||||
|
||||
// We have already processed these files, return the array
|
||||
// from cached version to make everything work faster
|
||||
$colors = json_decode(file_get_contents($test->destination));
|
||||
|
||||
} else {
|
||||
|
||||
echo "Processing data and saving to {$test->destination}\n";
|
||||
|
||||
// We don't have cached versions so process colors as an array
|
||||
$colors = $test->getPalette();
|
||||
|
||||
// And then save the data to file specified in $test->destination
|
||||
$test->save();
|
||||
|
||||
}
|
||||
|
||||
echo print_r($colors, true)
|
||||
. "</pre>\n";
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user