Files
card-spin/src/random/png.ts
xiao.xiong e974416760 update
2025-10-11 18:33:14 +08:00

16 lines
570 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 数字图片然后base64的图片
export const randomPng = (content: number | string = 1) =>{
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d')!;
const size = 128;
canvas.width = size;
canvas.height = size;
ctx.fillStyle = '#'+Math.floor(Math.random()*16777215).toString(16);
ctx.fillRect(0, 0, size, size);
ctx.font = 'bold 32px Arial';
ctx.fillStyle = '#ffffff';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText(content.toString(), size / 2, size / 2);
return canvas.toDataURL();
}