thedesk/app/main/img.js

43 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-05-19 17:39:30 +10:00
function img(mainWindow, dir) {
2019-04-03 14:59:29 +11:00
const electron = require("electron");
const dialog = electron.dialog;
const fs = require("fs");
var Jimp = require("jimp");
var ipc = electron.ipcMain;
const BrowserWindow = electron.BrowserWindow;
ipc.on('file-select', (e, args) => {
2019-05-19 17:39:30 +10:00
2019-04-03 14:59:29 +11:00
dialog.showOpenDialog(null, {
properties: ['openFile', 'multiSelections'],
title: '添付ファイルを選択',
defaultPath: '.',
filters: [
2019-05-19 17:39:30 +10:00
{ name: 'メディアファイル', extensions: ['jpg', 'png', 'gif', 'bmp', 'jpeg', 'mp4', 'webm'] },
{ name: '画像', extensions: ['jpg', 'png', 'gif', 'bmp', 'jpeg'] },
{ name: '動画', extensions: ['mp4', 'webm'] },
{ name: '全てのファイル', extensions: ['*'] }
2019-04-03 14:59:29 +11:00
]
}, (fileNames) => {
2019-05-19 17:39:30 +10:00
if (!fileNames) {
2019-04-03 14:59:29 +11:00
return false;
}
2019-05-19 17:39:30 +10:00
for (var i = 0; i < fileNames.length; i++) {
var path = fileNames[i];
2019-04-03 14:59:29 +11:00
var bin = fs.readFileSync(path, 'base64');
e.sender.webContents.send('bmp-img-comp', [bin, 'new']);
2019-04-03 14:59:29 +11:00
}
});
});
2019-05-19 17:39:30 +10:00
ipc.on('bmp-image', (e, args) => {
var m = args[0].match(/(.+)\\(.+)\.(.+)$/);
Jimp.read(args[0], function (err, lenna) {
if (err) throw err;
lenna.getBase64(Jimp.MIME_PNG, function (err, src) {
e.sender.webContents.send('bmp-img-comp', [src, args[1]]);
2019-05-19 17:39:30 +10:00
});
});
});
2019-04-03 14:59:29 +11:00
}
exports.img = img;