Image data related functions fix first commit. Needs more testing.