Skip to content

Commit

Permalink
Use File Saver library for cross-browser compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
shannonlui committed May 24, 2019
1 parent a8fece4 commit 39a4afa
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
5 changes: 5 additions & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"file-saver": "^2.0.2",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-redux": "^7.0.3",
Expand Down
11 changes: 2 additions & 9 deletions client/src/pages/ImageEditor/Canvas/Canvas.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { saveAs } from 'file-saver';

import styles from './Canvas.module.css';
import * as actions from '../../../store/actions';
Expand Down Expand Up @@ -63,15 +64,7 @@ class Canvas extends Component {

saveCanvas = () => {
const canvas = this.canvas.current;
if (canvas.msToBlob) {
// Save canvas as an image in IE
const blob = canvas.msToBlob();
window.navigator.msSaveBlob(blob, 'canvas.png');
} else {
// Save canvas as an image in Chrome/Firefox
const image = canvas.toDataURL('image/png').replace('image/png', 'image/octet-stream');
window.location.href = image;
}
saveAs(canvas.toDataURL('image/png'), 'pixelartify.png');
}

getClosestColor(colors, target) {
Expand Down

0 comments on commit 39a4afa

Please sign in to comment.