Fix: cannot upload

This commit is contained in:
cutls 2020-05-11 18:42:43 +09:00
parent 783ceec8de
commit c005b546ba

View File

@ -6,23 +6,20 @@ function img(mainWindow, dir) {
var ipc = electron.ipcMain var ipc = electron.ipcMain
const BrowserWindow = electron.BrowserWindow const BrowserWindow = electron.BrowserWindow
ipc.on('file-select', (e, args) => { ipc.on('file-select', (e, args) => {
dialog.showOpenDialog( let fileNames = dialog.showOpenDialogSync(mainWindow, {
null,
{
properties: ['openFile', 'multiSelections'], properties: ['openFile', 'multiSelections'],
title: '添付ファイルを選択', title: '添付ファイルを選択',
defaultPath: '.', defaultPath: '.',
filters: [ filters: [
{ {
name: 'メディアファイル', name: 'メディアファイル',
extensions: ['jpg', 'png', 'gif', 'bmp', 'jpeg', 'mp4', 'webm'] extensions: ['jpg', 'png', 'gif', 'bmp', 'jpeg', 'mp4', 'webm'],
}, },
{ name: '画像', extensions: ['jpg', 'png', 'gif', 'bmp', 'jpeg'] }, { name: '画像', extensions: ['jpg', 'png', 'gif', 'bmp', 'jpeg'] },
{ name: '動画', extensions: ['mp4', 'webm'] }, { name: '動画', extensions: ['mp4', 'webm'] },
{ name: '全てのファイル', extensions: ['*'] } { name: '全てのファイル', extensions: ['*'] },
] ],
}, })
fileNames => {
if (!fileNames) { if (!fileNames) {
return false return false
} }
@ -31,13 +28,11 @@ function img(mainWindow, dir) {
var bin = fs.readFileSync(path, 'base64') var bin = fs.readFileSync(path, 'base64')
e.sender.webContents.send('resizeJudgement', [bin, 'new']) e.sender.webContents.send('resizeJudgement', [bin, 'new'])
} }
}
)
}) })
ipc.on('bmp-image', (e, args) => { ipc.on('bmp-image', (e, args) => {
Jimp.read(args[0], function(err, lenna) { Jimp.read(args[0], function (err, lenna) {
if (err) throw err if (err) throw err
lenna.getBase64(Jimp.MIME_PNG, function(err, src) { lenna.getBase64(Jimp.MIME_PNG, function (err, src) {
e.sender.webContents.send('bmp-img-comp', [src, args[1]]) e.sender.webContents.send('bmp-img-comp', [src, args[1]])
}) })
}) })
@ -51,9 +46,9 @@ function img(mainWindow, dir) {
} }
var b64 = args[0].replace(/^data:\w+\/\w+;base64,/, '') var b64 = args[0].replace(/^data:\w+\/\w+;base64,/, '')
var decodedFile = new Buffer(b64, 'base64') var decodedFile = new Buffer(b64, 'base64')
Jimp.read(decodedFile, function(err, lenna) { Jimp.read(decodedFile, function (err, lenna) {
if (err) throw err if (err) throw err
lenna.scaleToFit(args[1], args[1]).getBase64(Jimp[use], function(err, src) { lenna.scaleToFit(args[1], args[1]).getBase64(Jimp[use], function (err, src) {
e.sender.webContents.send('bmp-img-comp', [src, args[1]]) e.sender.webContents.send('bmp-img-comp', [src, args[1]])
}) })
}) })
@ -63,9 +58,9 @@ function img(mainWindow, dir) {
var b64 = args[0].replace(/^data:\w+\/\w+;base64,/, '') var b64 = args[0].replace(/^data:\w+\/\w+;base64,/, '')
var decodedFile = new Buffer(b64, 'base64') var decodedFile = new Buffer(b64, 'base64')
console.log(text) console.log(text)
Jimp.read(decodedFile, function(err, image) { Jimp.read(decodedFile, function (err, image) {
if (err) throw err if (err) throw err
Jimp.loadFont(Jimp.FONT_SANS_16_BLACK).then(font => { Jimp.loadFont(Jimp.FONT_SANS_16_BLACK).then((font) => {
var evWidth = Jimp.measureText(font, text) var evWidth = Jimp.measureText(font, text)
var width = image.bitmap.width var width = image.bitmap.width
var height = image.bitmap.height var height = image.bitmap.height
@ -75,12 +70,12 @@ function img(mainWindow, dir) {
console.log(left, top, color) console.log(left, top, color)
var ave = (color.r + color.g + color.b) / 3 var ave = (color.r + color.g + color.b) / 3
if (ave > 128) { if (ave > 128) {
image.print(font, left, top, args[1]).getBase64(Jimp.MIME_PNG, function(err, src) { image.print(font, left, top, args[1]).getBase64(Jimp.MIME_PNG, function (err, src) {
e.sender.webContents.send('bmp-img-comp', [src, args[1], true]) e.sender.webContents.send('bmp-img-comp', [src, args[1], true])
}) })
} else { } else {
Jimp.loadFont(Jimp.FONT_SANS_16_WHITE).then(font => { Jimp.loadFont(Jimp.FONT_SANS_16_WHITE).then((font) => {
image.print(font, left, top, args[1]).getBase64(Jimp.MIME_PNG, function(err, src) { image.print(font, left, top, args[1]).getBase64(Jimp.MIME_PNG, function (err, src) {
e.sender.webContents.send('bmp-img-comp', [src, args[1], true]) e.sender.webContents.send('bmp-img-comp', [src, args[1], true])
}) })
}) })