'PIL thumbnail GIF distorted colors on LED matrix

I have a script that converts GIFs into smaller, 128x32 pixel size using .thumbnail. These GIFs are then displayed on a 128x32 LED matrix.

The problem is, when resized, and displayed on the LED matrix, GIFs with background colors end up looking very noisy, a lot of static, and distortion. However, for GIFs with just black backgrounds, they seem fine. Am I missing something? Perhaps this is a resampling issue?

Examples:

1. GIF with black background

enter image description here enter image description here

2. GIF with colored background enter image description here enter image description here

Look how noisy the 2nd GIF is compared to its original GIF.

def getUserGIFs(self):

f = open('csv/GIF_settings.json', 'r')
all_settings = json.load(f)
f.close()


for ind,fle in enumerate(all_settings['images']):
            
            try:
                GIF = Image.open(os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'user_uploads'), fle))
                frames = []

                    for i, frame in enumerate(ImageSequence.Iterator(GIF)):
                        
                        frame = frame.convert('P')
                        frame.thumbnail((128, 32),Image.LANCZOS)

                        f = self.stitchImage([frame])
                        frames.append(f)


                frames[0].save('./display_images/working_gif{}.gif'.format(str(ind)), save_all=True, append_images=frames[1:], loop=0, optimize = False)
                GIF = Image.open('./display_images/working_gif{}.gif'.format(str(ind)))
                GIFs.append(GIF)


            except Exception as e:
                logf = open('log.txt', "a")
                exc_type, exc_obj, exc_tb = sys.exc_info()
                fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
                logf.write(str(e))
                logf.write('. file: ' + fname)
                logf.write('. line: ' +  str(exc_tb.tb_lineno))
                logf.write('. type: ' +  str(exc_type))
                logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
                logf.close()

        return GIFs



Solution 1:[1]

Turned out my antivirus kept deleting the file without sending any notification, so I didn't know about it.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mentor93