forked from javierbyte/img2css
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
executable file
·84 lines (65 loc) · 1.94 KB
/
App.js
File metadata and controls
executable file
·84 lines (65 loc) · 1.94 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import React from 'react'
var _ = require('lodash')
var Dropzone = require('react-dropzone')
var base64ImageToRGBArray = require('./lib/base64ImageToRGBArray')
export const App = React.createClass({
getInitialState () {
return {
rgbArray: null,
loadingImage: false
}
},
onDrop (files) {
var file = files[0]
var fr = new window.FileReader()
if (window.ga) {
window.ga('send', 'event', 'button', 'click', 'img2css execute')
}
this.setState({
loadingImage: true
})
fr.onload = (data) => {
const base64 = data.currentTarget.result
base64ImageToRGBArray(base64, (err, data) => {
if (err) return console.error(err)
this.setState({
rgbArray: data,
loadingImage: false
})
})
}
fr.readAsDataURL(file)
},
render () {
var {rgbArray, loadingImage} = this.state
var masterShadow = _.map(rgbArray, (row, rowIndex) => {
return _.map(row, (col, colIndex) => {
return `rgb(${col.r},${col.g},${col.b}) ${colIndex ? colIndex + 'px' : 0} ${rowIndex ? rowIndex + 'px' : 0}`
}).join(',')
}).join(',')
return (
<div className='padding-horizontal-2x'>
<Dropzone onDrop={this.onDrop} className='dropZone'>
{loadingImage ? 'Processing...' : 'Drop an image here, or click to upload.'}
</Dropzone>
{rgbArray && (
<div>
<div className='tutorial'>
This is your pure css (and single div) image! Enjoy!
</div>
<div className='pixel' style={{
boxShadow: masterShadow,
marginBottom: rgbArray.length
}} />
<div className='tutorial'>
The code:
</div>
<div className='code'>
{`<div style="height: 1px; width: 1px; box-shadow: ${masterShadow}"></div>`}
</div>
</div>
)}
</div>
)
}
})