Merged Imagedraw rewrite

Continuation of #610, merged to master.