Color and quality loss with similar colors or from RGBA
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 38/100
- Type d'issue
- Bug
- Clarté
- Plutôt claire
- Activité
- À l'abandon
- Stack technique
- python
- Domaine
- computer-graphics
Piste de recherche
Start by running the two Python scripts against the supplied Sample files.zip and compare the GIF and PNG outputs, focusing on the GIF export path for similar colors and RGBA frames. Reproduce both cases, then trace the relevant Pillow GIF-saving entry point and add regression coverage; done means the reported color loss is explained and the affected export behavior is corrected or clearly documented.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Hello,
I have found 2 cases where PIL reduces color quality, when I import a gif animation as PIL images, and then save it again as a gif animation.
Case 1: Importing a gif animation with similar background colors removes differentiated background:
This is the gif animation with a checkered background:

After importing it as PIL format images, and then exporting it again as a gif, the colors get reduced, and you cannot see the checkered pattern of the background anymore:

The code used is this:
from PIL import Image as Img
#Convert Gif Frames into PIL images:
tempimage = Img.open("GIF before import.gif")
ExportFrames = []
durationFrame=None
for i in range(0, tempimage.n_frames):
tempimage.seek(i)
ExportFrames.append(tempimage.copy())
if durationFrame == None:
durationFrame = tempimage.info['duration']
ExportFrames[0].save("GIF after export.gif", disposal=2, save_all=True,
append_images=ExportFrames[1:], loop=0,
duration=durationFrame, optimize=False, lossless=True)
Case 2: Adding Alpha Channel to PIL images, before saving as gif:
I added this additional step of pasting each frame unto a transparent alpha PIL image, because for some GIFs, when I imported them and then saved them, the first main frame of the GIF would not have a transparent background. This would be fixed by adding this step.
However with it this quality loss occurs:
The original GIF image that I import as PIL formatted images:

After saving, there is an extreme quality loss:

This quality loss does only occur when adding the step.
However, even with the step added, there is no quality loss when exporting the frames as single png images instead as a gif animation:

This suggests that error happens during GIF export.
The code used for this is the following:
from PIL import Image as Img
#Correct the first frame of gif animations:
def CreateFrameWithAlphaValue(CurrentImage,size):
width,height=size
edited_frame = Img.new('RGBA', (width, height))
edited_frame.putalpha(0)
edited_frame.paste(CurrentImage, (0, 0))
return edited_frame
#Convert Gif Frames into PIL images:
tempimage = Img.open("GIF before import.gif")
ExportFrames = []
durationFrame=None
for i in range(0, tempimage.n_frames):
tempimage.seek(i)
ExportFrames.append(tempimage.copy())
if durationFrame == None:
durationFrame = tempimage.info['duration']
#Add Alpha Channel to all gifs in order to avoid erroneous first frames:
for x in range(0,len(ExportFrames)):
ExportFrames[x]=CreateFrameWithAlphaValue(ExportFrames[x],ExportFrames[0].size).copy()
ExportFrames[0].save("GIF after export.gif", disposal=2, save_all=True,
append_images=ExportFrames[1:], loop=0,
duration=durationFrame, optimize=False, lossless=True)
I also attach the sample images and python scripts above here so anyone can recreate the issue:
Sample files.zip
Running convert('P') on every PIL frame image did not solve the issue.
How can I stop and control the quality loss in both of these cases? Why is this happening? Is this a potential bug?
- Langage dominant
- Python
- Étoiles
- 14k
- Forks
- 2.6k
- Merge moyen
- 1 j 1 h
- PR mergées (30 j)
- 205
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de python-pillow/Pillow
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
python-pillow/Pillow#10590 ·
Les mainteneurs répondent en général sous 1 jour
-
Image.thumbnail() raises ZeroDivisionError when the target height is 0Peut-être pris Une pull request liée à cette issue est ouverte ou déjà fusionnée. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
python-pillow/Pillow#10589 ·
Les mainteneurs répondent en général sous 1 jour
-
Sun raster files with RLE encoding and odd-width rows decode shiftedPeut-être pris @PerryLink l’a pris il y a 21 jours. Ouverte🤖-assisted
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
python-pillow/Pillow#10370 · 3 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Warn that pre-applying arabic_reshaper + python-bidi corrupts text on a Raqm buildPeut-être pris @Syamjith-NK l’a pris il y a 85 jours. OuverteDocumentation Font Rendering PNG Third Party Framework
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
python-pillow/Pillow#9907 · 3 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Example code in ImageText documentation makes incorrect use of get_bbox()Peut-être pris @mmporong l’a pris il y a 1 jour. OuverteDocumentation
Difficulté 1/5 Moins d'une heure Accessibilité débutants 25/100
python-pillow/Pillow#10583 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de python-pillow/Pillow
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
vllm-project/vllm#69304 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
interpreter-core type-bug
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
Les mainteneurs répondent en général sous 1 jour
-
pydanty:is-working
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
pydantic/pydantic-ai#14187 ·
Les mainteneurs répondent en général sous 1 jour
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
Les mainteneurs répondent en général sous 1 jour
-
test
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
prebid/salesagent#2676 ·
Les mainteneurs répondent en général sous 1 jour