Set the origin to the top left position of the gcode coordinates
Do a first pass over the file to calculate the x/y extents of the G0/G1 commands in order to determine the extents of the final drawing. With this information determined, re-position the draw commands such that the bottom-left corner of the image extents is the origin.