Created
December 14, 2019 12:02
-
-
Save andreasvirkus/29d3d7d87f461202f25f3ddf36efe0c9 to your computer and use it in GitHub Desktop.
Stitch together 2 images and screenshot them
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
export const screenshot = (canvasRef, base, avatar) => { | |
const ctx = canvasRef.getContext('2d') | |
const imageObj1 = new Image() | |
const imageObj2 = new Image() | |
imageObj1.src = base.src | |
imageObj1.onload = () => { | |
ctx.drawImage(imageObj1, 0, 0, base.height, base.width) | |
imageObj2.src = avatar.src | |
imageObj2.onload = () => { | |
ctx.drawImage(imageObj2, avatar.left, avatar.top, avatar.height, avatar.width) | |
// const img = canvasRef.toDataURL('image/png') | |
// document.write('<img src="' + img + '" width="328" height="526"/>') | |
return canvasRef | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment