Hello.

At work there is a program that saves a photo of a person in a text file.

-9j-4AAQSkZJRgABAQEAYABgAAD-2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBA...

And so on. There are many characters. How do I convert characters back to an image?

Thank you in advance.

  • one
    What kind of program? Usually, base64 is used to convert binary data into text. - morin
  • The point is not in the program, but in how to translate into an image, I will go to understand. Thank. - kapamba

1 answer 1

To translate a stream of characters into an image, you need to know the algorithm by which the image was translated into a stream of characters. An example for a hexadecimal view.

In hex

 f = open("from.jpg", "rb") i = f.read() s = binascii.hexlify(i) 

Of hex

 ff = open("from.jpg", "r") ii = ff.read() ss = binascii.unhexlify(ii) 
  • In my case, the base64 module helped. z is a string of characters. with open ('12 .jpeg ',' wb ') as f_pdf: pdfname = base64.b64decode (z,'! - ') f_pdf.write (pdfname) - kapamba