png-exif-reader-script
/work4aiで使用するpngからExif情報を抜き出してページに書き込むscript code:script.js
scrapbox.PageMenu.addMenu({
title: 'input image',
onClick: () => {
let ifelm = document.createElement("input");
ifelm.type = "file";
ifelm.onchange = function (input) {
let reader = new FileReader();
reader.onload = function () {
let result = new Uint8Array(reader.result);
let index = readbinary(result);
let txt = "";
let body = "";
for (let i = 1; i < index.length; i++) {
txt = txt + "code:" + indexi.split("\x00").join("\n ") + "\n"; }
body = encodeURI(txt)
// 新しいタブで入力
window.open(/${scrapbox.Project.name}/${scrapbox.Page.title}?body=${body})
}
reader.readAsArrayBuffer(input.target.files0); }
ifelm.click();
}
})
// 画像のバイナリを取得
function readbinary(result) {
let k = "";
for (let i = 0; i < result.length; i++) {
k = k + readhex(resulti.toString(16)); }
let arr = k.split("tEXt");
let index = arr.map(e => {
let k = e.split("IDAT")0; return k.slice(0, -8);
})
return index;
}
// 16進数を文字列に
function readhex(s) {
var result = "";
var tester = "";
for (var i = 0; i < s.length / 2; ++i) {
result += String.fromCharCode("0x" + s.slice(i * 2, (i + 1) * 2));
}
return result;
}