I want to re-convert a binary equivalent file which contains "1"s and "0"s back to its JPG format (or convert it back to binary)
i.e i have a file which contains all 1's and 0's which i converted from a jpg image using the following function
def convert_binary(inpath, outpath):
byte2str = ["{:08b}".format(i) for i in range(256)]
with open(inpath, "rb") as fin:
with open(outpath, "w") as fout:
data = fin.read(1024)
while data:
for b in map(ord, data):
fout.write(byte2str[b])
data = fin.read(1024)
convert_binary("image.jpg", "binary_file.txt")
thanks to Tim Peters
I now want to convert this back (1's and 0's) back to its original image, any help would be grateful.
P.S: I am really sorry for such trivial questions, i am a biotechnology major and python programming is not my forte. I am experimenting with an app for my thesis and have got stuck.