1 Star 0 Fork 0

IcingTomato/simple-tool-pages

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
coffee-time.html 2.22 KB
一键复制 编辑 原始数据 按行查看 历史
dmscode 提交于 2019-06-03 17:23 . flip-clock
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Coffee Time.</title>
<style>
body {
text-align: center;
}
#can {
display: none;
}
#show {
display: block;
margin: 10px auto;
width: 30%;
min-width: 320px;
}
#words {
display: block;
margin: 10px auto;
width: 60%;
min-width: 480px;
height: 320px;
padding: 20px;
font-size: 24px;
font-family: '楷体';
text-align: center;
}
</style>
</head>
<body>
<canvas id="can"></canvas>
<img src="src/Coffee-Time.png" id="show">
<a href="#" id="link">= 点此下载图片 =</a>
<textarea id="words"></textarea>
<script>
const input = document.getElementById('words')
const canvas = document.getElementById('can')
const link = document.getElementById('link')
const img = document.getElementById('show')
const ctx = canvas.getContext('2d')
const image = new Image()
let imageData
image.onload = function() {
w = canvas.width = image.width
h = canvas.height = image.height
ctx.drawImage(image, 0, 0)
ctx.font = "80px 楷体"
ctx.textAlign = "center"
ctx.fillStyle = "#05316E"
ctx.shadowBlur = 1.2
ctx.shadowColor = "rgba(5, 49, 112, .2)"
imageData = ctx.getImageData(0, 0, canvas.width, canvas.height)
}
image.src = "src/Coffee-Time.png"
const startX = 960
const startY = 534
const lineHeight = 100
let timer
input.addEventListener('keyup',()=>{
window.clearTimeout(timer)
timer = window.setTimeout(()=>{
ctx.putImageData(imageData, 0, 0)
const words = input.value.split(/\n/g)
let x = startX
let y = startY
for(const word of words){
ctx.fillText(word, x, y)
y += lineHeight
}
canvas.toBlob(function (blobObj) {
link.href = window.URL.createObjectURL(blobObj)
link.download = 'Coffee-Time.png'
})
img.src = canvas.toDataURL("image/png")
}, 500)
})
</script>
</body>
</html>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/IcingTomato/simple-tool-pages.git
git@gitee.com:IcingTomato/simple-tool-pages.git
IcingTomato
simple-tool-pages
simple-tool-pages
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385