I would like to save a PIL.ImageTk.PhotoImage into a file. My approach is to create a file "with open" and call the "write" method, but it wont't work, because I don't know how to get the byte-array from the object.
def store_temp_image(data, image):
new_file_name = data.number + ".jpg"
with open(os.path.join("/tmp/myapp", new_file_name), mode='wb+') as output:
output.write(image)
The error message is as follows:
TypeError: a bytes-like object is required, not 'PhotoImage'
I usually find approaches to convert ImageTk Objects into PIL objects, but not the other way round. From the docs I couldn't get any hints neither.