Skip to content

Commit 789de6f

Browse files
committed
v1.1 Reduce runtimes, compress images before uploading
1 parent b04ad96 commit 789de6f

File tree

6 files changed

+46
-5
lines changed

6 files changed

+46
-5
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"homepage": "https://matthew29tang.github.io/hypervision/",
66
"dependencies": {
77
"@material-ui/core": "^4.1.1",
8+
"browser-image-compression": "^1.0.6",
89
"gh-pages": "^2.1.1",
910
"react": "^16.9.0",
1011
"react-copy-to-clipboard": "^5.0.1",

src/components/Logo.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react';
2+
import { withStyles } from '@material-ui/core/styles';
3+
import './Pages.css';
4+
5+
const styles = theme => ({
6+
logo: {
7+
marginTop: "150px",
8+
marginBottom: "150px",
9+
},
10+
});
11+
12+
class Logo extends React.Component {
13+
14+
render() {
15+
const { classes } = this.props;
16+
return (
17+
<div className={classes.logo}>
18+
<img src={require("./ocr-icon.png")} alt="logo"/>
19+
</div>
20+
);
21+
}
22+
}
23+
24+
export default withStyles(styles)(Logo);

src/components/Router/Router.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Grid from '@material-ui/core/Grid';
1212

1313
import About from "../About.js";
1414
import Vision from "../Vision.js";
15+
import Logo from "../Logo.js";
1516

1617
const styles = theme => ({
1718
root: {
@@ -28,6 +29,7 @@ const routing = (
2829
<Switch>
2930
<Route exact path="/" component={Vision} />
3031
<Route path="/about" component={About} />
32+
<Route path="/logo" component={Logo} />
3133
</Switch>
3234
</div>
3335
</Router>

src/components/Upload.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import imageCompression from 'browser-image-compression';
23
import Divider from '@material-ui/core/Divider';
34
import Dropzone from './Dropzone/Dropzone.js';
45
import Progress from './Progress/Progress.js';
@@ -17,6 +18,8 @@ class Upload extends React.Component {
1718
uploadProgress: {},
1819
successfullUploaded: false
1920
};
21+
// Ping the backend so we can get it spinning
22+
fetch(BACKEND_URL);
2023
}
2124

2225
onFilesAdded = (file) => {
@@ -48,10 +51,17 @@ class Upload extends React.Component {
4851
uploadFiles = (file) => {
4952
this.setState({ uploadProgress: {}, uploading: true });
5053
try {
51-
this.sendRequest(file);
54+
var options = {
55+
maxSizeMB: 1,
56+
maxWidthOrHeight: 1920,
57+
}
58+
imageCompression(file, options)
59+
.then(compressed => {
60+
this.sendRequest(compressed)
61+
})
5262
this.setState({ successfullUploaded: true, uploading: false });
5363
} catch (e) {
54-
this.setState({ successfullUploaded: true, uploading: false });
64+
this.setState({ successfullUploaded: false, uploading: false });
5565
}
5666
}
5767

@@ -83,7 +93,6 @@ class Upload extends React.Component {
8393

8494
const formData = new FormData();
8595
formData.append("image", file, "image");
86-
console.log("Uploading...");
8796
req.open("POST", BACKEND_URL);
8897
req.send(formData);
8998
req.onreadystatechange = () => {
@@ -114,7 +123,7 @@ class Upload extends React.Component {
114123
<div id="Files">
115124
Uploading image...
116125
<br/>
117-
(this can take up to 5-10 secs for large images)
126+
(this can take up to 5 secs for large images)
118127
{/*
119128
<div key={this.state.files.name} id="Row">
120129
{this.renderProgress(this.state.files)}

src/components/ocr-icon.png

6.35 KB
Loading

0 commit comments

Comments
 (0)