Skip to content

Instantly share code, notes, and snippets.

@andreasvirkus
Created December 14, 2019 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreasvirkus/29d3d7d87f461202f25f3ddf36efe0c9 to your computer and use it in GitHub Desktop.
Save andreasvirkus/29d3d7d87f461202f25f3ddf36efe0c9 to your computer and use it in GitHub Desktop.
Stitch together 2 images and screenshot them
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