Add an improved function for flipping images.