Failed to execute 'drawImage' on 'CanvasRenderingContext2D

AFAICT, your code looks actually good. Any chances to share a live example that demonstrates the runtime error. I want to debug why your code fails at this line: