Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

heic対応(v0.4.0) #28

Merged
merged 6 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Looks Good To Neo Image Generator via clipboard

## summary

クリップボードから画像データを貼り付けして、LGTNテキストを合成した画像をクリップボードに書き込むツールです
クリップボードから画像データを貼り付けして、LGTN(LGTM)テキストを合成した画像をクリップボードに書き込むツールです

[現在公開しているGithub Pagesへのリンク](https://haruyan-hopemucci.github.io/lgtn/)

Expand All @@ -13,10 +13,16 @@ Looks Good To Neo Image Generator via clipboard
- 書き込んだクリップボードの画像はそのままGithubのIssueやPullRequestのテキストボックスにペーストすることができる
- フロントエンド(javascript)だけで実装されているのでサーバーレス運用が可能。

## Supported file formats

- image/jpeg
- image/png
- image/heic (v0.4.0以降)

## Supported Environments

- Windows10
- Google Chrome 119以降
- Microsoft Edge 119以降
- MacOS Venture
- Google Chrome 119以降
- Google Chrome 119以降
3 changes: 2 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<title>LGTN Generator</title>
<script src="https://code.jquery.com/jquery-3.7.1.min.js"
integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
<script src="./js/heic2any.js"></script>
<script src="./js/app.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous" />
Expand All @@ -18,7 +19,7 @@

<body>
<main class="container">
<h1>LGTN Generator <small>v0.3.0</small></h1>
<h1>LGTN Generator <small>v0.4.0</small></h1>
<div id="paste-area">
<div id="paste-area-message">
クリップボードにコピーした画像をペーストしてください。
Expand Down
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
285 changes: 285 additions & 0 deletions docs/js/heic2any.js

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions survey/heic-convert-test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
#target {
max-width: 100vw;
}
img {
max-width: 100%;
}
</style>
</head>
<body>
<h1>target</h1>
<div id="target"></div>

<script src="../docs/js/heic2any.js"></script>
<script>
fetch("./test.heic")
.then((res) => res.blob())
.then((blob) =>
heic2any({
blob,
})
)
.then((conversionResult) => {
var url = URL.createObjectURL(conversionResult);
document.getElementById(
"target"
).innerHTML = `<a target="_blank" href="${url}"><img src="${url}"></a>`;
})
.catch((e) => {
console.log(e);
});
</script>
</body>
</html>
Binary file added survey/test.heic
Binary file not shown.