Moves image encoding functionality to image.go