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

Cannot Add White Text with Black Outline To This Gif in P mode #4475

Closed
alanyee opened this issue Mar 15, 2020 · 1 comment
Closed

Cannot Add White Text with Black Outline To This Gif in P mode #4475

alanyee opened this issue Mar 15, 2020 · 1 comment

Comments

@alanyee
Copy link

alanyee commented Mar 15, 2020

What did you do?

I am following the guidance given here #3128 with the following gif:
test

What did you expect to happen?

I was hoping to get white text with a black outline such as this:
out2

This is possible via converting the frame to RGB or RGBA, but there seems to be some weird fuzz when I convert the frames.

What actually happened?

I get brown text with a fuzzy black outline:
out

On other gifs, I get white text, but the text_stroke is not black:
out

What are your OS, Python and Pillow versions?

  • OS: Ubuntu 18.04.4 LTS
  • Python: 3.6.9
  • Pillow: 7.0.0
import io
import sys

from PIL import Image, ImageDraw, ImageFont, ImageSequence

# This gif opens up in P mode
black = 0
white = 251
padding = 1
size = 40
fnt = ImageFont.truetype('impact.ttf', size)
im = Image.open('Pictures/test.gif')
# A list of the frames to be outputted
x = 0
y = 0
text = sys.argv[1]
frames = []
for frame in ImageSequence.Iterator(im):
    # Draw the text on the frame
    d = ImageDraw.Draw(frame)

    d.text((x, y), text, font=fnt, fill=white, stroke_width=1, stroke_fill=black)
    del d
    b = io.BytesIO()
    frame.save(b, format="GIF")
    frame = Image.open(b)
    # Then append the single frame image to a list of frames
    frames.append(frame)
# Save the frames as a new image
frames[0].save('Pictures/out.gif', save_all=True, append_images=frames[1:])
@alanyee
Copy link
Author

alanyee commented Mar 16, 2020

Nevermind, I realize the limitations of palette mode now, though I am still uneasy about the drop in picture quality during the conversion.

@alanyee alanyee closed this as completed Mar 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant