I am trying to generate a PNG
image which contains some custom text.
While creating the new image canvas there are multiple options to choose the mode of the image (Ex: P, PA, RGB, RGBA etc).
When I use the P
mode, the rendered text is not anti-aliased.
Size of the result image is considerably smaller when used P
mode compared to other modes like RGB, RGBA so, this would be my preference.
I would like to know why the font rendering is dependent on the color pallet? Is P
mode (8-bit pixels ) with 256 colors are not sufficient to render the font?
When I use several of these png
images as frames and generate a GIF
image out of it, the quality of the image is reduced drastically.
As discussed on this thread, I do not want to resize the image which is a time consuming operation.
Below is the code which I have used:
fnt = ImageFont.truetype('Assets/somefont.ttf',82)
b = Image.new('P',(680,120),color=255)
#b = Image.new('RGB',(680,120),color=255)
draw = ImageDraw.Draw(b)
#draw.fontmode = "0"
draw.text((b.width/2, (b.height-50)/2), "88", fill=0, font=fnt)
f = BytesIO()
b.save(f, format='PNG')