BBSysDyn
BBSysDyn

Reputation: 4601

PIL Draw.text and Lower Resolution

I have the following PIL code to print text in an image

import os, sys
import PIL
from PIL import ImageFont
from PIL import Image
from PIL import ImageDraw

img = Image.open("one.jpg")
draw = ImageDraw.Draw(img)    
font = ImageFont.truetype("/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman.ttf",27)
draw.text((100, 100), "test test test", font=font)    
img.save("out.jpg")

This works on one.jpg file. However on another test file called two.jpg, it doesn't print anything. From what I see, the only difference between two documents is the lower resolution on two.jpg. The file one.jpg is 200x200 dpi, two.jpg is 60x60 dpi.

How can I get draw.text to work in lower res?

Thanks,

Upvotes: 1

Views: 1845

Answers (1)

unutbu
unutbu

Reputation: 879739

You need to specify a color for the text:

import os
import sys
import ImageFont
import Image
import ImageDraw

img = Image.open("two.jpg")
draw = ImageDraw.Draw(img)    
font = ImageFont.truetype("/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman.ttf",27)
draw.text((100, 100), "test test test", font=font, fill = 'blue')    
img.save("out.jpg")

Upvotes: 2

Related Questions