You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to split gif into frames and save as PNG.
The issue is, some gifs are low quality and when getting to the second frame onwards, the frames are corrupted.
this is the code I'm using:
importloggingimportosfromPILimportImagefromloggerimportLoggertoddler_lq='/Users/noambaron/Downloads/toddler_LQ.gif'toddler_dir='/Users/noambaron/Desktop/toddler_f'gif_path=toddler_lqframe_dir=toddler_dirlogger=Logger(logging.INFO, 'gif_test')
try:
frame=Image.open(gif_path)
palette=frame.palettenum_of_frames=0whileframe:
base_name=os.path.basename(gif_path).split('.')[0]
frame.show()
frame.save(os.path.join(frame_dir, '%s-%s.png'% (base_name, num_of_frames)), 'PNG')
num_of_frames+=1try:
frame.seek(num_of_frames)
exceptEOFError:
breakexceptExceptionase:
logger.error('failed extracting frames from gif %s due to %s', gif_path, e)
attached is the gif, and the 3 first frames
The text was updated successfully, but these errors were encountered:
importPILfromPILimportImagefromPILimportImageOpsfromPILimportGifImagePlugingif=Image.open('/home/pi/Photos/ANIMATION.gif')
# for frame in ImageSequence.Iterator(gif):forninrange(0,gif.n_frames):
gif.seek(n)
im=ImageOps.grayscale(gif)
im.save("/home/pi/Photos/tmp/gif_{}.bmp".format(n))
I'm trying to split gif into frames and save as PNG.
The issue is, some gifs are low quality and when getting to the second frame onwards, the frames are corrupted.
this is the code I'm using:
attached is the gif, and the 3 first frames
The text was updated successfully, but these errors were encountered: