Skip to content

Commit abb0e1e

Browse files
committed
Made the results about 30% smaller
1 parent 035a780 commit abb0e1e

File tree

5 files changed

+28
-15
lines changed

5 files changed

+28
-15
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"dependencies": {
4141
"lodash": "^3.10.1",
4242
"react": "^0.13.0",
43-
"react-dropzone": "^2.2.1"
43+
"react-dropzone": "^2.2.1",
44+
"tinycolor2": "^1.1.2"
4445
}
4546
}

src/App.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
import React from 'react'
2+
import tinycolor from 'tinycolor2'
23

34
var _ = require('lodash')
45
var Dropzone = require('react-dropzone')
56

67
var base64ImageToRGBArray = require('./lib/base64ImageToRGBArray')
78

9+
function compressColor (rgb) {
10+
var hex = tinycolor(rgb).toHexString()
11+
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
16+
}
17+
}
18+
819
export const App = React.createClass({
920

1021
getInitialState () {
@@ -46,7 +57,9 @@ export const App = React.createClass({
4657

4758
var masterShadow = _.map(rgbArray, (row, rowIndex) => {
4859
return _.map(row, (col, colIndex) => {
49-
return `rgb(${col.r},${col.g},${col.b}) ${colIndex ? colIndex + 'px' : 0} ${rowIndex ? rowIndex + 'px' : 0}`
60+
var color = compressColor(`rgb(${col.r},${col.g},${col.b})`)
61+
62+
return `${color} ${colIndex ? colIndex + 'px' : 0} ${rowIndex ? rowIndex + 'px' : 0}`
5063
}).join(',')
5164
}).join(',')
5265

@@ -60,10 +73,12 @@ export const App = React.createClass({
6073
{rgbArray && (
6174
<div>
6275
<div className='tutorial'>
63-
This is your pure css (and single div) image! Enjoy!
76+
This is your pure css (and single div) image! Enjoy! {masterShadow.length.toLocaleString()}b
6477
</div>
6578

6679
<div className='pixel' style={{
80+
height: 1,
81+
width: 1,
6782
boxShadow: masterShadow,
6883
marginBottom: rgbArray.length
6984
}} />

static/bundle.js

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

static/bundle.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

style/main.css

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@ h1 {
2727
padding: 0 2em;
2828
}
2929

30-
.pixel {
31-
height: 1px;
32-
width: 1px;
33-
background: #000;
34-
}
30+
.pixel {}
3531

3632
.dropZone {
3733
height: 150px;

0 commit comments

Comments
 (0)