I tried adding text to a GIF file but it seems to have messed up the file. When I now open it, it looks like what you get when you have white noise on an old TV, but with some bits still showing part of the original GIF. Could someone help me debug?
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
import numpy
import imageio
img = Image.open('test.gif')
sequence = []
frameNo = 0
while True:
try:
img.seek(frameNo)
except EOFError:
break
newimg = Image.new("RGB", img.size)
newimg.paste(img)
draw = ImageDraw.Draw(newimg);
draw = ImageDraw.Draw(newimg)
# font = ImageFont.truetype(<font-file>, <font-size>)
font = ImageFont.truetype("arial.ttf", 30
)
# draw.text((x, y),"Sample Text",(r,g,b))
draw.text((0, 0),"Sample Text",(255,255,255),font=font)
open_cv_image = numpy.array(newimg)
sequence.append(open_cv_image)
frameNo += 1
imageio.mimsave('temp.gif', sequence);