def modify(self, function, *args, **kwargs):
""" Modify the image object using the given Image function.
This function supplies sequence support. """
if not gif_support or not self.gif:
self.object = function(self.object, *args, **kwargs)
else:
frames = []
duration = self.object.info.get("duration") / 1000
for frame in ImageSequence.Iterator(self.object):
frame_bytes = utils.convert_image_object(function(frame, *args, **kwargs))
frames.append(imageio.imread(frame_bytes, format="PNG"))
# Save the image as bytes and recreate the image object
image_bytes = imageio.mimwrite(imageio.RETURN_BYTES, frames, format=self.format, duration=duration)
self.object = Image.open(BytesIO(image_bytes))
self.gif_bytes = image_bytes
评论列表
文章目录