Skip to content

Commit

Permalink
feature: アスキーアートをダウンロードできるようにする
Browse files Browse the repository at this point in the history
  • Loading branch information
weweweok committed Apr 18, 2024
1 parent eda9dce commit a62c4d5
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions islands/ImageForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@ export default function ImageForm() {
buttonDisable.value = false;
isAnnounsing.value = false;
};

const downloadAsciiArt = () => {
const asciiArtPreview = document.getElementById(
"ascii-art",
) as HTMLImageElement;
const asciiArt = asciiArtPreview.src;
console.log(asciiArt);
const download = document.createElement("a");
download.href = asciiArt;
download.download = "ascii-art.png";
document.body.appendChild(download);
download.click();
document.body.removeChild(download);
};

return (
<div class="content-center items-center self-center translate-x-1/4">
<form action="post">
Expand Down Expand Up @@ -103,6 +118,13 @@ export default function ImageForm() {
: undefined}
<img id="preview" class="max-w-xs max-h-56 " />
<img id="ascii-art" src="" class="max-w-xs max-h-56 content-center" />
<button
onClick={() => {
downloadAsciiArt();
}}
>
アスキーアートをダウンロード
</button>
</div>
);
}

0 comments on commit a62c4d5

Please sign in to comment.