Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange gif background color #2734

Closed
retsyo opened this issue Sep 13, 2017 · 3 comments
Closed

Strange gif background color #2734

retsyo opened this issue Sep 13, 2017 · 3 comments
Labels
Anaconda Issues with Anaconda's Pillow Bug Any unexpected behavior, until confirmed feature. GIF Memory Palette
Projects

Comments

@retsyo
Copy link

retsyo commented Sep 13, 2017

I am using PILLOW 4.2.1-py36_0 which is updated by conda from Python 3.6.0 |Anaconda custom (64-bit)| (default, Dec 23 2016, 11:57:41) [MSC v.1900 64 bit (AMD64)] on win32

I found sometimes the produced gif has strange background.

  1. I only find this with Stcaiyun.ttf
  2. Even for Stcaiyun.ttf, sometimes the gif is ok
  3. The framexx.png is ok
import random
from PIL import Image, ImageDraw, ImageFont

frames = []
for frame in range(10):
    img = Image.new(size=(320, 200), mode='RGB', color='white')
    
    drw = ImageDraw.Draw(img)
    text = '% 2i' % frame
    font = ImageFont.truetype(r'd:\WINDOWS\Fonts\STCAIYUN.TTF', 80)
    #~ font = ImageFont.truetype(r'd:\WINDOWS\Fonts\Stfangso.ttf', 80)
    #~ font = ImageFont.truetype(r'd:\WINDOWS\Fonts\times.TTF', 80)
    #~ font = ImageFont.truetype(r'3Dkirieji.ttf', 80)
    x, y=random.randint(60,250), random.randint(20,100)
    color = random.choice(['red', 'green', 'blue', (0, 127, 127)])
    drw.text((x, y), text, font=font, fill=color)
    img.save('frame%02i.png' % frame)
    frames.append(img)
    
frames[0].save('out.gif', save_all=True, append_images=frames[1:], duration=300, loop=True, optimize=True)

I am sorry I cannot upload STCAIYUN.TTF since it is some huge

out.zip

@wiredfool
Copy link
Member

This looks similar to the other GIF palette issues, #1717, #1987, etc. And if not similar, it's still tied up in it.

It's possible that the optimize flag is throwing it off, compressing all the colors in the palettes to the 0,1 indexes. And optimize is not doing anything for you here.

(Aside -- Optimize is a horrible name, because everyone wants optimization. But it's effect is removing unused colors from the palette, saving a max of 760 bytes/frame in the best case (palette entries at 0,255), at the cost of visiting every pixel 5 times and making 3 extra copies of the image in memory)

@retsyo
Copy link
Author

retsyo commented Sep 13, 2017

it seems that optimize=False produces right gif

@radarhere radarhere changed the title strange gif background color Strange gif background color Feb 16, 2018
@aclark4life aclark4life added this to Backlog in Pillow May 11, 2019
@aclark4life aclark4life moved this from Backlog to Icebox in Pillow May 11, 2019
@aclark4life aclark4life added the Bug Any unexpected behavior, until confirmed feature. label May 11, 2019
@radarhere
Copy link
Member

Installing Pillow 4.2.1 from source, I'm unable to replicate.

Pillow automation moved this from Icebox to Closed Mar 17, 2021
@aclark4life aclark4life added the Anaconda Issues with Anaconda's Pillow label May 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Anaconda Issues with Anaconda's Pillow Bug Any unexpected behavior, until confirmed feature. GIF Memory Palette
Projects
Pillow
  
Closed
Development

No branches or pull requests

4 participants