diff --git a/app/js/platform/end.js b/app/js/platform/end.js index 5dbe5758..7a64922e 100644 --- a/app/js/platform/end.js +++ b/app/js/platform/end.js @@ -138,7 +138,7 @@ onmessage = function(e) { } else if (e.data[0] == 'udg') { udg(e.data[1][0], e.data[1][1]) } else if (e.data[0] == 'media') { - media(e.data[1][0], e.data[1][1], e.data[1][2]) + media(e.data[1][0], e.data[1][1], e.data[1][2], e.data[1][3]) } else if (e.data[0] == 'post') { post('pass') } else if (e.data[0] == 'toastSaved') { diff --git a/app/js/platform/preload.js b/app/js/platform/preload.js index 0dbacfbc..b8afa588 100644 --- a/app/js/platform/preload.js +++ b/app/js/platform/preload.js @@ -13,6 +13,10 @@ onmessage = function(e) { ipc.send('dialogStore', e.data[1]) } else if (e.data[0] == 'bmpImage') { ipc.send('bmp-image', e.data[1]) + } else if (e.data[0] == 'resizeImage') { + ipc.send('resize-image', e.data[1]) + } else if (e.data[0] == 'stampImage') { + ipc.send('stamp-image', e.data[1]) } else if (e.data[0] == 'dialogCW') { ipc.send('dialogCW', e.data[1]) } else if (e.data[0] == 'nativeNotf') { @@ -112,7 +116,31 @@ ipc.on('theme-css-response', function(event, arg) { }) //img.js ipc.on('bmp-img-comp', function(event, b64) { - postMessage(['media', [b64[0], 'image/png', b64[1]]], '*') + if (b64[2]) { + var stamped = true + } else { + var stamped = false + } + postMessage(['media', [b64[0], 'image/png', b64[1], stamped]], '*') +}) +ipc.on('resizeJudgement', function(event, b64) { + var resize = localStorage.getItem('uploadCrop') * 1 + if (resize > 0) { + var element = new Image() + var width + element.onload = function() { + var width = element.naturalWidth + var height = element.naturalHeight + if (width > resize || height > resize) { + ipc.send('resize-image', [b64, resize]) + } else { + postMessage(['media', [b64[0], 'image/png', b64[1]]], '*') + } + } + element.src = b64 + } else { + postMessage(['media', [b64[0], 'image/png', b64[1]]], '*') + } }) //ui,img.js ipc.on('general-dl-prog', function(event, arg) { diff --git a/app/js/post/img.js b/app/js/post/img.js index 9001bcf3..7d6a7cd9 100644 --- a/app/js/post/img.js +++ b/app/js/post/img.js @@ -60,6 +60,24 @@ function handleFileUpload(files, obj, no) { var fr = new FileReader() fr.onload = function(evt) { var b64 = evt.target.result + var resize = localStorage.getItem('uploadCrop') * 1 + if (resize > 0) { + var element = new Image() + var width + element.onload = function() { + var width = element.naturalWidth + var height = element.naturalHeight + if (width > resize || height > resize) { + postMessage(['resizeImage', [b64, resize]], '*') + return false + } else { + $('#b64-box').val(b64) + var ret = media(b64, files['type'], no) + } + } + element.src = b64 + return false + } $('#b64-box').val(b64) var ret = media(b64, files['type'], no) } @@ -68,7 +86,15 @@ function handleFileUpload(files, obj, no) { } //ファイルアップロード -function media(b64, type, no) { +function media(b64, type, no, stamped) { + var acct_id = $('#post-acct-sel').val() + var domain = localStorage.getItem('domain_' + acct_id) + var user = localStorage.getItem('user_' + acct_id) + if ($('#stamp').hasClass('stamp-avail') && !stamped) { + postMessage(['stampImage', [b64, user + '@' + domain]], '*') + return false + } + console.log(b64) var l = 4 var c = 'abcdefghijklmnopqrstuvwxyz0123456789' var cl = c.length @@ -88,8 +114,6 @@ function media(b64, type, no) { var media = toBlob(b64, type) var fd = new FormData() fd.append('file', media) - var acct_id = $('#post-acct-sel').val() - var domain = localStorage.getItem('domain_' + acct_id) var at = localStorage.getItem('acct_' + acct_id + '_at') var httpreq = new XMLHttpRequest() if (localStorage.getItem('mode_' + domain) == 'misskey') { @@ -104,7 +128,6 @@ function media(b64, type, no) { } var previewer = 'url' fd.append('i', at) - //fd.append('isSensitive', nsfw); httpreq.send(fd) } else { var previewer = 'preview_url' @@ -133,11 +156,7 @@ function media(b64, type, no) { } var img = localStorage.getItem('img') if (json.type.indexOf('image') != -1) { - var html = `` + var html = `` $('#preview').append(html) } else { $('#preview').append(lang.lang_postimg_previewdis) @@ -300,3 +319,12 @@ function altImage(acct_id, id) { } }) } +function stamp() { + if ($('#stamp').hasClass('stamp-avail')) { + $('#stamp').html('Off') + $('#stamp').removeClass('stamp-avail') + } else { + $('#stamp').html('On') + $('#stamp').addClass('stamp-avail') + } +} \ No newline at end of file diff --git a/app/js/post/post.js b/app/js/post/post.js index e5500f31..5ee63405 100644 --- a/app/js/post/post.js +++ b/app/js/post/post.js @@ -295,6 +295,8 @@ function clear() { $('#nsfw').removeClass('yellow-text') $('#nsfw').html('visibility_off') $('#nsfw').removeClass('nsfw-avail') + $('#stamp').html('Off') + $('#stamp').removeClass('stamp-avail') $('#nsc').text(lang.lang_nothing) $('#drag').css('background-color', '#e0e0e0') $('#preview').html('') diff --git a/app/main/img.js b/app/main/img.js index 7a855a4a..28a78cc3 100644 --- a/app/main/img.js +++ b/app/main/img.js @@ -1,43 +1,92 @@ function img(mainWindow, dir) { - 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) => { - - dialog.showOpenDialog(null, { - properties: ['openFile', 'multiSelections'], - title: '添付ファイルを選択', - defaultPath: '.', - filters: [ - { name: 'メディアファイル', extensions: ['jpg', 'png', 'gif', 'bmp', 'jpeg', 'mp4', 'webm'] }, - { name: '画像', extensions: ['jpg', 'png', 'gif', 'bmp', 'jpeg'] }, - { name: '動画', extensions: ['mp4', 'webm'] }, - { name: '全てのファイル', extensions: ['*'] } - ] - }, (fileNames) => { - if (!fileNames) { - return false; - } - for (var i = 0; i < fileNames.length; i++) { - var path = fileNames[i]; - var bin = fs.readFileSync(path, 'base64'); - e.sender.webContents.send('bmp-img-comp', [bin, 'new']); - } - }); - }); - 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]]); - }); - }); - - }); + 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) => { + dialog.showOpenDialog( + null, + { + properties: ['openFile', 'multiSelections'], + title: '添付ファイルを選択', + defaultPath: '.', + filters: [ + { + name: 'メディアファイル', + extensions: ['jpg', 'png', 'gif', 'bmp', 'jpeg', 'mp4', 'webm'] + }, + { name: '画像', extensions: ['jpg', 'png', 'gif', 'bmp', 'jpeg'] }, + { name: '動画', extensions: ['mp4', 'webm'] }, + { name: '全てのファイル', extensions: ['*'] } + ] + }, + fileNames => { + if (!fileNames) { + return false + } + for (var i = 0; i < fileNames.length; i++) { + var path = fileNames[i] + var bin = fs.readFileSync(path, 'base64') + e.sender.webContents.send('resizeJudgement', [bin, 'new']) + } + } + ) + }) + ipc.on('bmp-image', (e, args) => { + 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]]) + }) + }) + }) + ipc.on('resize-image', (e, args) => { + var ext = args[0].toString().slice(args[0].indexOf('/') + 1, args[0].indexOf(';')) + if (ext == 'jpeg') { + var use = 'MIME_JPEG' + } else { + var use = 'MIME_PNG' + } + var b64 = args[0].replace(/^data:\w+\/\w+;base64,/, '') + var decodedFile = new Buffer(b64, 'base64') + Jimp.read(decodedFile, function(err, lenna) { + if (err) throw err + lenna.scaleToFit(args[1], args[1]).getBase64(Jimp[use], function(err, src) { + e.sender.webContents.send('bmp-img-comp', [src, args[1]]) + }) + }) + }) + ipc.on('stamp-image', (e, args) => { + var text = args[1] + var b64 = args[0].replace(/^data:\w+\/\w+;base64,/, '') + var decodedFile = new Buffer(b64, 'base64') + console.log(text) + Jimp.read(decodedFile, function(err, image) { + if (err) throw err + Jimp.loadFont(Jimp.FONT_SANS_16_BLACK).then(font => { + var evWidth = Jimp.measureText(font, text) + var width = image.bitmap.width + var height = image.bitmap.height + var left = width - evWidth - 10 + var top = height - 30 + var color = Jimp.intToRGBA(image.getPixelColor(left, top)) + console.log(left, top, color) + var ave = (color.r + color.g + color.b) / 3 + if (ave > 128) { + 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]) + }) + } else { + Jimp.loadFont(Jimp.FONT_SANS_16_WHITE).then(font => { + 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]) + }) + }) + } + }) + }) + }) } -exports.img = img; \ No newline at end of file +exports.img = img diff --git a/app/main/system.js b/app/main/system.js index 2d19e760..a671f241 100644 --- a/app/main/system.js +++ b/app/main/system.js @@ -45,7 +45,7 @@ function system(mainWindow, dir, lang, dirname) { //エクスポートのダイアログ ipc.on("exportSettings", function(e, args) { dialog.showSaveDialog( - null, + mainWindow, { title: "Export", properties: ["openFile", "createDirectory"], @@ -62,13 +62,14 @@ function system(mainWindow, dir, lang, dirname) { //インポートのダイアログ ipc.on("importSettings", function(e, args) { dialog.showOpenDialog( - null, + mainWindow, { title: "Import", properties: ["openFile"], filters: [{ name: "TheDesk Config", extensions: ["thedeskconfig", "thedeskconfigv2", "json5"] }] }, fileNames => { + console.log("imported from: ", fileNames) if (!fileNames) { return false; } @@ -79,7 +80,7 @@ function system(mainWindow, dir, lang, dirname) { //保存フォルダのダイアログ ipc.on("savefolder", function(e, args) { dialog.showOpenDialog( - null, + mainWindow, { title: "Save folder", properties: ["openDirectory"] @@ -92,7 +93,7 @@ function system(mainWindow, dir, lang, dirname) { //カスタムサウンドのダイアログ ipc.on("customSound", function(e, arg) { dialog.showOpenDialog( - null, + mainWindow, { title: "Custom sound", properties: ["openFile"], diff --git a/app/view/make/index.sample.html b/app/view/make/index.sample.html index b8561b19..ff9c3f6b 100644 --- a/app/view/make/index.sample.html +++ b/app/view/make/index.sample.html @@ -205,9 +205,11 @@