So I have a .jpg/.png and I opened it up in Text Edit which I provided below:
Is there anyway I can save these exotic symbols to a string in Python to later write that to a file to produce an image?
I tried to import a string that had the beta symbol in it and I got an error that send Non-ASCII so I am assuming the same would happen for this.
Is there anyway to get around this problem?
Thanks
Portion of Image.png in Text Edit:
What you are looking at in your text edit is a binary file, trying to represent it all in human readable characters.
Just open the file as binary in python:
with open('picture.png', 'rb') as f:
data = f.read()
with open('picture_out.png', 'wb') as f:
f.write(data)
You can read to file in binary format by providing the rb
flag to open
and then just save what ever comes out of the file into a text file. I don't know what the point of this would be but there you go
# read in image data
fh = open('test.png','rb')
data = fh.read()
fh.close()
# write gobbledigoock to text file
fh = open('test.txt','w')
fh.write(data)
fh.close
fh.close()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.