我发现我不能用 HTML 做到这一点(在图片中添加文本),我找到了一种使用 JAVA 的方法,但我很想通过使用 Javascript 找到一种方法。
最佳答案
你可以用 Canvas 来做,
<canvas id="canvas" width="340" height="340"></canvas>
脚本,
function addTextToImage(imagePath, text) {
var circle_canvas = document.getElementById("canvas");
var context = circle_canvas.getContext("2d");
// Draw Image function
var img = new Image();
img.src = imagePath;
img.onload = function () {
context.drawImage(img, 0, 0);
context.lineWidth = 1;
context.fillStyle = "#CC00FF";
context.lineStyle = "#ffff00";
context.font = "18px sans-serif";
context.fillText(text, 50, 50);
};
}
addTextToImage("http://www.gravatar.com/avatar/0c7c99dec43bb0062494520e57f0b9ae?s=256&d=identicon&r=PG", "Your text");
关于javascript - 如何使用 javaScript 在图片文件 (png) 中添加文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16947494/