Encoding the canvas image to JPEG