Skip to content

Commit 5615587

Browse files
committed
Merge pull request javierbyte#16 from Need4Video/patch-1
Bug fixed & compression optimized using CSS color names
2 parents ebeb132 + 804ea4b commit 5615587

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/App.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,18 @@ var base64ImageToRGBArray = require('./lib/base64ImageToRGBArray')
99
function compressColor (rgb) {
1010
var hex = tinycolor(rgb).toHexString()
1111

12-
if (hex[1] === hex[2] && hex[3] === hex[4] && hex[5] === hex[6]) {
13-
return '#' + hex[1] + hex[3] + hex[4]
14-
} else {
15-
return hex
12+
switch (hex) { // based on CSS3 supported color names http://www.w3.org/TR/css3-color/
13+
case '#c0c0c0': return 'silver';
14+
case '#808080': return 'gray';
15+
case '#800000': return 'maroon';
16+
case '#ff0000': return 'red';
17+
case '#800080': return 'purple';
18+
case '#008000': return 'green';
19+
case '#808000': return 'olive';
20+
case '#000080': return 'navy';
21+
case '#008080': return 'teal';
1622
}
23+
return hex[1] === hex[2] && hex[3] === hex[4] && hex[5] === hex[6] ? "#" + hex[1] + hex[3] + hex[5] : hex;
1724
}
1825

1926
export const App = React.createClass({

0 commit comments

Comments
 (0)