Let's put some of the last code together and see what happens... smile and text...
from PIL import Image,ImageDraw,ImageFont # sample text and font unicode_text = u"Smile World!" font = ImageFont.truetype("consola.ttf", 28, encoding="unic") # get the line size text_width, text_height = font.getsize(unicode_text) # create a blank canvas with extra space between lines canvas = Image.new('RGB', (text_width + 10, text_height + 100), "orange") # draw the text onto the text canvas, and use black as the text color draw = ImageDraw.Draw(canvas) draw.text((5,5), u'Hello World!', 'blue', font) def smile(x=30,y=30): draw = ImageDraw.Draw(canvas) draw.ellipse((0+x,0+y,90+x,90+y),'yellow','blue') # face draw.ellipse((25+x,20+y,35+x,30+y),'yellow','blue') # left eye draw.ellipse((28+x,25+y,32+x,30+y),'blue','blue') # left ... draw.ellipse((50+x,20+y,60+x,30+y),'yellow','blue') # right eye draw.ellipse((53+x,25+y,58+x,30+y),'blue','blue') # right ... draw.arc((40+x,50+y,50+x,55+y), 0, 360, 0) # nose draw.arc((20+x,40+y,70+x,70+y), 0, 180, 0) # smile smile(50,28) canvas.show()
Comments
Post a Comment