-
Notifications
You must be signed in to change notification settings - Fork 0
/
attach.html
34 lines (30 loc) · 1.08 KB
/
attach.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<!DOCTYPE html>
<html>
<head>
<title>Add Text to Image</title>
</head>
<body>
<img id="image" src="img/玉米.jpg" alt="Your Image">
<canvas id="canvas"></canvas>
<script>
window.onload = function () {
const image = document.getElementById("image");
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
canvas.width = image.width;
canvas.height = image.height;
ctx.drawImage(image, 0, 0);
ctx.font = "bold 70px system-ui";
ctx.fillStyle = "#000";
ctx.fillText("蘇裔非非非非", 150, 370);
const imageWithText = new Image();
imageWithText.src = canvas.toDataURL("image/png");
const downloadLink = document.createElement("a");
downloadLink.href = imageWithText.src;
downloadLink.download = "image_with_text.png";
downloadLink.innerHTML = "Download Image with Text";
document.body.appendChild(downloadLink);
}
</script>
</body>
</html>