Made the image to canvas code more portable