I took code I had to dump hexadecimal image data and added a binary option to it ,,,
# hexadecimal and binary dump of image file data
# modified to work with Python30
# pick an image file you have in the working directory
# or give the full file path ...
image_file = 'py.ico'
fin = open(image_file, "rb")
data = fin.read()
print("Image file %s not found" % imageFile)
# convert every byte of data to the corresponding 2-digit hexadecimal
hex_str = str(binascii.hexlify(data))
# now create a list of 2-digit hexadecimals
hex_list = 
bin_list = 
for ix in range(2, len(hex_str)-1, 2):
hex = hex_str[ix]+hex_str[ix+1]
bin_str = "".join(bin_list)
The binary string output is pretty useless, since you can never recover any data back.
If you want to send binary image data as a string, you have to use Python module base64.
This is exactly what I needed. I know I can't recover any data back. But I'm gonna use it to feed it through a neural net. Seeing the output I think it's not very effective analysing image data (I'm now using PIL for that). But I think it can be very useful while analysing textinput with a neuralnet!