1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
async function getBillbordCanvas({ img, ratio, width, height, text, textFontSize = '36px', textPositionX = width / 10 + 10, textPositionY = height / 2 + 15 }) { return new Promise(resolve => { const canvas = document.createElement("canvas"); const ctx = canvas.getContext("2d");
canvas.style.opacity = 1; canvas.width = width * ratio; canvas.height = height * ratio;
ctx.scale(ratio, ratio); const image = new Image(); image.src = img; image.onload = function () { ctx.drawImage(image, 0, 0, width, height); ctx.font = `bold ${textFontSize} YouSheBiaoTiHei`; const gradient = ctx.createLinearGradient(0, 5, 0, canvas.height - 45); gradient.addColorStop(0, "#FFFFFF"); gradient.addColorStop(1, "#ffffff"); ctx.fillStyle = gradient; ctx.fillText(text, textPositionX, textPositionY); resolve(canvas) }; }) }
|