Skip to content

Instantly share code, notes, and snippets.

@acknpop
Created July 12, 2017 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acknpop/bbc83020dedc90c28c5161836400c72d to your computer and use it in GitHub Desktop.
Save acknpop/bbc83020dedc90c28c5161836400c72d to your computer and use it in GitHub Desktop.
--- package.json.orig Tue Jul 04 14:39:29 2017
+++ package.json Wed Jul 12 18:19:16 2017
@@ -19,5 +19,8 @@
"homepage": "https://github.com/anydown/mangadown#readme",
"devDependencies": {
"buble": "^0.15.2"
+ },
+ "dependencies": {
+ "data-uri-to-buffer": "0.0.4"
}
}
--- index.js.orig Thu Jun 29 09:57:00 2017
+++ index.js Wed Jul 12 18:27:05 2017
@@ -67,6 +67,19 @@
var w = 420 + 20 * 2
var h = (280 + 20) * 4 + 20
+const remote = require('electron').remote
+const os = remote.require('os')
+const fs = remote.require('fs')
+
+const path = require('path')
+const desktopDirName = 'Desktop'
+const homeDirPath = os.homedir()
+const desktopDirPath = path.join(homeDirPath, desktopDirName)
+
+const dataUriToBuffer = remote.require('data-uri-to-buffer')
+const dialog = remote.dialog
+
new Vue({
el: "#app",
data: {
@@ -141,7 +154,26 @@
destCtx.fillRect(0, 0, w, h)
destCtx.drawImage(canvas, 0, 0);
destCtx.drawImage(fabel, 0, 0);
- window.open(eimage.toDataURL('image/png'));
+ //window.open(eimage.toDataURL('image/png'));
+ const canvasDataUrl = eimage.toDataURL('image/png')
+ const decoded = dataUriToBuffer(canvasDataUrl)
+ dialog.showSaveDialog(null, {
+ title: '画像の保存',
+ defaultPath: desktopDirPath,
+ filters: [
+ { name: 'PNG File', extensions: ['png']},
+ { name: 'All Files', extensions: ['*'] }
+ ]
+ }, (saveFiles) => {
+ fs.writeFile(saveFiles, decoded, (err) => {
+ if (err) {
+ window.alert('ファイルの保存に失敗しました')
+ console.log(err)
+ } else {
+ window.alert('ファイルを保存しました')
+ }
+ });
+ });
},
redraw: function () {
var text = this.input
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment