I want to handle a screenshot as an opened file, it more specifically has to have the attribute .read()
.
I'm taking the screenshot using PIL's ImageGrab.grab()
which gives me an Image-Object, which obviously doesn't have the .read()
attribute. I know that I could save the image and reopen it with open("image.png", "rb")
but I would like to know if there is an easy way to do this without having to save the image in the process.
I want to add the image to an email with the help of smtplib. Usually, I would do this:
filename='filename'
attachment =open(filename,'rb')
part = MIMEBase('application','octet-stream')
part.set_payload((attachment).read())
encoders.encode_base64(part)
part.add_header('Content-Disposition',"attachment; filename= "+filename)
msg.attach(part)
but in this case, I want to use the screenshot taken before.