diff options
-rw-r--r-- | index.php | 29 |
1 files changed, 28 insertions, 1 deletions
@@ -112,7 +112,33 @@ function domcolor_mode($img, $flt) return false; } -$domalgos = array('mean', 'mode'); + +function domcolor_custom($img, $flt) +{ + $color = $_POST['customcolor']; + + /* Remove prefixing '#' if present. */ + if ($color[0] == '#') $color = substr($color, 1); + + if (strlen($color) == 6) { + /* Handle rrggbb format. */ + $r = $color[0].$color[1]; + $g = $color[2].$color[3]; + $b = $color[4].$color[5]; + } elseif (strlen($color) == 3) { + /* Handle rgb format. */ + $r = $color[0].$color[0]; + $g = $color[1].$color[1]; + $b = $color[2].$color[2]; + } else { + /* Unknown format. */ + return false; + } + + return array(hexdec($r), hexdec($g), hexdec($b)); +} + +$domalgos = array('mean', 'mode', 'custom'); $colfilters = array('none', 'pure', 'grey', 'grey5'); function extract_dominant_color($svg, $algo = 'average', $filter = 'grey') @@ -374,6 +400,7 @@ echo '<?xml version="1.0" encoding="utf-8" ?>'; <legend>Algorithm for dominant color extraction</legend> <label><input type="radio" name="domalgo" value="mean" />Mean / Average</label> <label><input type="radio" name="domalgo" value="mode" checked="true" />Mode</label> + <label><input type="radio" name="domalgo" value="custom" checked="true" />Custom: <input type="text" name="customcolor" /></label> </fieldset> <fieldset> <legend>Colors to ignore</legend> |