-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpalette.php
executable file
·43 lines (35 loc) · 1.08 KB
/
palette.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
class Palette implements ArrayAccess{
static private $_cache = array();
private $_maxIterations;
private $_image;
public function __construct($maxIterations, $image) {
$this->_maxIterations = $maxIterations;
$this->_image = $image;
}
public function offsetSet($offset, $value) {
return;
}
public function offsetExists($offset) {
return $offset < $this->_maxIterations || 'inside' == $offset || 'scale' == $offset;
}
public function offsetUnset($offset) {
return;
}
public function offsetGet($offset) {
if (isset(self::$_cache[$offset])) {
return self::$_cache[$offset];
}
if ('inside' == $offset) {
$return = imagecolorallocate($this->_image, 0, 0, 0);
} else if ('scale' == $offset) {
$return = imagecolorallocate($this->_image, 255, 255, 255);
} else {
// $green = $offset / $this->_maxIterations *255;
$green = log($offset)/log($this->_maxIterations)* 255;
$return = imagecolorallocate($this->_image, 255, $green, 70);
}
self::$_cache[$offset] = $return;
return $return;
}
}