imagewriter: correctly write files with non-jpg extensions