Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PIL imageText
#1
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:

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.
Reply


Messages In This Thread
PIL imageText - by tony1812 - Aug-20-2017, 05:01 PM
RE: PIL imageText - by Larz60+ - Aug-20-2017, 05:25 PM
RE: PIL imageText - by tony1812 - Aug-20-2017, 07:31 PM
RE: PIL imageText - by Larz60+ - Aug-20-2017, 09:32 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020