Created
August 16, 2019 05:58
-
-
Save nexpr/fb9186c1e0d5c6a37221837790679118 to your computer and use it in GitHub Desktop.
clipboard api write image demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<div> | |
<input type="color" id="color"> | |
<input id="text"> | |
<button id="wac">Write & Copy</button> | |
</div> | |
<div> | |
<canvas id="canvas" width=400 height=40 style="border: 1px solid silver"></canvas> | |
</div> | |
<script> | |
wac.onclick = () => { | |
const ctx = canvas.getContext("2d") | |
ctx.clearRect(0, 0, canvas.width, canvas.height) | |
ctx.fillStyle = color.value | |
ctx.font = "20px seif" | |
ctx.fillText(text.value, 15, 25) | |
const blob = canvas.toBlob(blob => { | |
navigator.clipboard.write([ | |
new ClipboardItem({ [blob.type]: blob }) | |
]) | |
}) | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment