Factor out canvas serialization algorihtm from HTMLCanvasElement to seperate file. This makes it usable by other things too.