Created
May 6, 2023 03:43
-
-
Save bliotti/07644f6c98ecaac618ee5f1907e636ce to your computer and use it in GitHub Desktop.
Stack images with canvas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.... | |
const generateCardImage = async (cardNumber, cardChoices) => { | |
const canvas = createCanvas(format.width, format.height); | |
const ctx = canvas.getContext("2d"); | |
console.log("Creating #", cardNumber) | |
ctx.clearRect(0, 0, format.width, format.height); | |
ctx.globalAlpha = 1; | |
ctx.globalCompositeOperation = "source-over"; | |
const foo = async (choice, index) => { | |
const layerNum = index | |
const tt = await getImage(layerNum, choice) | |
ctx.drawImage( | |
tt, | |
0, | |
0, | |
format.width, | |
format.height | |
) | |
} | |
let layerNum = 1 | |
for await (const x of cardChoices) { | |
foo(x, layerNum) | |
layerNum++ | |
} | |
const cornerLayer = await loadImage("./input/Overall_Card_Corners/CardCorners.png") | |
ctx.drawImage( | |
cornerLayer, | |
0, | |
0, | |
format.width, | |
format.height | |
) | |
writeCardImage(canvas.toBuffer(), cardNumber) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment