Converts an image to a byte array