0
returning images in python
can a function return an image file and, if yes, how do you do it? Iâve tried normally returning it (return and then the image file name)but it didnât work.
1 Answer
+ 3
Depends on what you want to do with it.
If you want image bytes :
with open("filepath/filename","rb") as f:
image=f.read()
return image
But you might not know what to do with that. There is a library called Pillow which handles images well, you'll want to :
from PIL import Image
def function(imagePath):
img=Image.open(imagePath)
return Image
These won't really be possible on SoloLearn (the first example could if you set it up correctly by writing the image file).
Your question is a bit vague so let me know if my awnsers are unrelated.