some code to get the image data, but its buggy