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.

27th Apr 2019, 5:48 PM
Jérémy Matte
Jérémy Matte - avatar
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.
27th Apr 2019, 7:40 PM
Ahri Fox
Ahri Fox - avatar