Take the 2-minute tour ×

I have a python script that is writing text to images using the PIL. Everything this is working fine except for when I encounter strings with carriage returns in them. I need to preserve the carriage returns in the text. Instead of writing the carriage return to the image, I get a little box character where the return should be. Here is the code that is writing the text:

 draw = ImageDraw.Draw(blankTemplate)
 draw.text((35 + attSpacing, 570),str(attText),fill=0,font=attFont)

attText is the variable that I am having trouble with. I'm casting it to a string before writing it because in some cases it is a number.

Thanks for you help.

share|improve this question

1 Answer 1

up vote 6 down vote accepted

Let's think for a moment. What does a "return" signify? It means go to the left some distance, and down some distance and resume displaying characters.

You've got to do something like the following.

y, x = 35, 570
for line in attText.splitlines():
    draw.text( (x,y), line, ... )
    y = y + attSpacing
share|improve this answer
great, that worked. thank you. –  Casey Apr 14 '09 at 17:42

Your Answer


