I'm trying to make a program that gets an image from URL. It returns first frame of the gif if the image is animated and just an image if it's not animated.
Code:
def is_animated(im):
try:
im.seek(1)
return True
except EOFError:
return False
def getImg(url):
img = Image.open(requests.get(url, stream=True).raw, mode='r')
if is_animated(img):
return img
else:
print('no animation detected')
return img
Problem: I tried it with an animated picture: it returned True in is_animated()
, but it doesn't return an Image object in return img
. Errors logs are blank. What can be the problem here? I will appreciate any help, thank you in advance.