Start removing dependency from template.gif
Move header writing to separate function
Move image compression to separate function
Extract block writing to separate function
Fix global table generation