我正在开发一个网络应用程序。它使用来自API的信息为游戏生成签名。
我需要使用脚本存储图像,该脚本收集信息并将其转换为图像。
你知道把text + CSS变成图片的方法吗?
发布于 2013-07-12 23:36:19
是的,这是可以做到的,您要做的是在画布上绘制文本,然后保存画布。您不需要显示画布,您可以像隐藏任何其他html元素一样隐藏它,只需添加它,在上面绘制文本,然后保存它。
下面是一个保存的库的链接:https://github.com/hongru/canvas2image
在画布上绘制文本的一些示例代码:
<canvas id="myCanvas" width="200" height="100" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>
<script>
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.font="30px Arial";
ctx.fillText("Your Text",10,50);
// save img
Canvas2Image.saveAsImage(c, 200, 100, 'png');
</script>
https://stackoverflow.com/questions/17618574
复制相似问题