I am trying to create an image upload utility in Hug / python and wanted to save images and gifs. But on uploading some of the gif images, the gif images seem to be a lot pixelated. Given below is the code snippet that I am using in the upload utility.
image = Image.open(io.BytesIO(file))
frames = [frame.copy() for frame in ImageSequence.Iterator(image)]
image.save(media_location, save_all=True, append_images=frames)
Fixed it!
The workaround can be not passing the animated images with PIL and directly storing it with a context manager
.
if image.is_animated:
with open(media_location, 'wb') as fp:
fp.write(byte_stream)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.