Consider the following code: from PIL import Image, ImageDraw, ImageFont
def addText(img, lTxt):
FONT_SIZE = 10
INTERLINE_DISTANCE = FONT_SIZE + 1
font = ImageFont.truetype('arial.ttf', FONT_SIZE)
lTxtImageHeight = INTERLINE_DISTANCE * len(lTxt)
# create text image
lTxtImg = Image.new('RGBA', (img.size[1], lTxtImageHeight), 255)
lTxtImgDraw = ImageDraw.Draw(lTxtImg, )
for (i, line) in enumerate(lTxt):
lTxtImgDraw.text((5, i * INTERLINE_DISTANCE), line, font=font, fill='#000000')
# rotate text image
lTxtImg = lTxtImg.rotate(90)
# create new transparent image ret
ret = Image.new('RGBA', (img.size[0] + lTxtImageHeight, img.size[1]), 255)
# paste the image to ret
ret.paste(img, (0,0))
# paste the text to ret
ret.paste(lTxtImg, (img.size[0], 0), lTxtImg)
return ret
img = Image.open('in.png')
addText(img, ['lorem', 'ipsum', 'dolores']).save('out.png')
Here are the input and the output files This is the input
and this is the output
As you may see, the output image contains a lot of reddish noise around the text. How can I eliminate this dithering?