Files
tunnel-cloud-web/src/components/content/tunnelScene/utils/toImg.js
2023-12-14 10:26:29 +08:00

16 lines
455 B
JavaScript

/**
* @param {String} text 把输入的文字转化为base64的img图片
*/
export default function (text, width = 100, height = 50) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "white";
ctx.fillRect(0, 0, width, height);
ctx.fillStyle = "black";
ctx.font = "30px serif";
ctx.fillText(text, 0, 30);
return canvas.toDataURL();
}