Skip to content

Commit

Permalink
feat: heicファイル対応
Browse files Browse the repository at this point in the history
  • Loading branch information
haruyan-hopemucci committed Dec 2, 2023
1 parent 31154e2 commit 032c495
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions docs/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,30 @@ $(function () {
setMessage("ペーストされたデータが画像ではありません");
return true;
}

setMessage("LGTN画像を生成しています...");

generateLGTN(event.clipboardData.items[0]);
const fileType = event.clipboardData.items[0].type
switch (fileType) {
case 'image/heic':
convertHeicToPng(event.clipboardData.items[0])
break
case 'image/png':
case 'image/jpeg':
generateLGTN(event.clipboardData.items[0])
break
default:
setMessage("未対応の画像形式です。");
}
});

const convertHeicToPng = async function (clipboardItem) {
const imageFile = clipboardItem.getAsFile();
const conversionResult = await heic2any({ blob: imageFile })
const dataUrl = URL.createObjectURL(conversionResult)
const imgEl = document.querySelector("#pasted-image");
imgEl.addEventListener("load", drawCanvas);
imgEl.src = dataUrl;
}

const generateLGTN = async function (clipboardItem) {
const imageFile = clipboardItem.getAsFile();
const imgEl = document.querySelector("#pasted-image");
Expand Down

0 comments on commit 032c495

Please sign in to comment.