唐润平:上线版,功能为待完善
This commit is contained in:
15
src/components/content/tunnelScene/utils/toImg.js
Normal file
15
src/components/content/tunnelScene/utils/toImg.js
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* @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();
|
||||
}
|
||||
Reference in New Issue
Block a user