views:

596

answers:

1

Hello,

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:

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

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.

+4  A: 

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
S.Lott
great, that worked. thank you.
Casey