随机生成canvas参数!

📅 发布时间:2026/7/16 1:29:13 👁️ 浏览次数:
随机生成canvas参数!
const { createCanvas } require(canvas); function generateCanvasFingerprint() { const canvas createCanvas(200, 50); const ctx canvas.getContext(2d); // 随机生成各种参数 const text Math.random().toString(36).substring(2, 10); const fontSize Math.floor(Math.random() * 10) 12; // 12-22px const colors [ #f60, #069, #cc0, #39d, #e71, rgba(${Math.floor(Math.random()*255)},${Math.floor(Math.random()*255)},${Math.floor(Math.random()*255)},0.7) ]; // 绘制底色矩形 ctx.fillStyle colors[Math.floor(Math.random() * colors.length)]; ctx.fillRect(125, 1, 62, 20); // 绘制主文字 ctx.textBaseline top; ctx.font ${fontSize}px Arial; ctx.fillStyle colors[Math.floor(Math.random() * colors.length)]; ctx.fillText(text, 2, 15); // 绘制半透明文字模拟真实指纹的叠加效果 ctx.fillStyle colors[5]; // 随机半透明色 ctx.fillText(text, 4, 17); // 添加随机噪点 for (let i 0; i 50; i) { ctx.fillStyle rgba(${Math.random()*255},${Math.random()*255},${Math.random()*255},0.5); ctx.fillRect(Math.random() * 200, Math.random() * 50, 2, 2); } return canvas.toDataURL(); } console.log(generateCanvasFingerprint());