Aug-20-2017, 05:01 PM
Hello, I am practicing use PIL to ouput text on screen. But I donot fin a clear answer about using draw,text.
My code is like this:
But it is the option the confuses me. draw.text((0,16), "looooooooooooong text", fill=255, font=?????)
Whst do I need to do to make the font size bigger or change font family? Thanks.
My code is like this:
import RPi.GPIO as GPIO import time import Adafruit_GPIO.SPI as SPI import Adafruit_SSD1306 from PIL import Image from PIL import ImageDraw from PIL import ImageFont from PIL import ImageEnhance RST = None # 128x64 display with hardware I2C: disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST) # Initialize library. disp.begin() # Clear display. disp.clear() disp.display() # Create blank image for drawing. # Make sure to create image with mode '1' for 1-bit color. width = disp.width height = disp.height image = Image.new('1', (width, height)) # Get drawing object to draw on image. draw = ImageDraw.Draw(image) # Draw a black filled box to clear the image. #draw.rectangle((0,0,width,height), outline=0, fill=0) #draw a text #font = ImageFont.truetype("media/text/fonts/" + font + ".ttf", fontsize, encoding="unic") draw.text((0,16), "looooooooooooong text", fill=255) disp.image(image) disp.display() time.sleep(.01)The output diplays just fine by using the default draw.text((0,16), "looooooooooooong text", fill=255)
But it is the option the confuses me. draw.text((0,16), "looooooooooooong text", fill=255, font=?????)
Whst do I need to do to make the font size bigger or change font family? Thanks.