Quantcast
Channel: WP快站
Viewing all articles
Browse latest Browse all 233

PIL text issue when making gif

$
0
0

I'm trying to use PIL/Pillow to make a meme with a GIF. I noticed that whenever I convert it to RGB, the text is messed up(not showing up white/is somewhat transparent and black) but the background is perfect, but if I switch it to RGBA, the background gets messed up missing huge spots of color and the text is perfect. I saw something about possibly using libimagequantize but PIL doesn't come with this due to licenseing and I couldn't ever figure how to install it with it.

https://imgur.com/a/5A7OlCY<-- The middle one showed up differently when uploaded but when I download it or upload to discord it shows the same on my computer.

from PIL import Image, ImageDraw, ImageFont, ImageSequencewith Image.open("conch.gif") as img:    frames = []    for frame in ImageSequence.Iterator(img):        frame = frame.convert("RGB")        draw = ImageDraw.Draw(frame)        font = ImageFont.truetype("./font/impacted.ttf", 30)        text = "Hello World!"        width, height = frame.size        x = (width / 2) - (font.getlength(text) / 2)        y = -5        draw.text((x, y), text, font=font, fill="white", stroke_width=3, stroke_fill="black")        frames.append(frame)    frames[0].save("conchquestion.gif", save_all=True, append_images=frames[1:], loop=0, duration=img.info['duration'], transparency=0, disposal=2)

Viewing all articles
Browse latest Browse all 233

Trending Articles