Messy version of bounding box
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -5,3 +5,4 @@ __pycache__
|
|||||||
old
|
old
|
||||||
Scripts
|
Scripts
|
||||||
pyvenv.cfg
|
pyvenv.cfg
|
||||||
|
share
|
||||||
|
|||||||
50
imagegen.py
50
imagegen.py
@@ -1,18 +1,27 @@
|
|||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
import datetime
|
import datetime
|
||||||
import pytz
|
import pytz
|
||||||
#import asyncio
|
|
||||||
import google_weather
|
import google_weather
|
||||||
import mlb
|
import mlb
|
||||||
#from getweather impor]t getweather
|
|
||||||
|
fontBaseHeight = 25
|
||||||
|
fnt = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",fontBaseHeight)
|
||||||
|
fntBold = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf",fontBaseHeight)
|
||||||
|
fntBigBold = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf",fontBaseHeight+10)
|
||||||
|
|
||||||
|
def WriteTextBlock(text, context, font = fnt, column=0, row=0, anchor = "la"):
|
||||||
|
context.multiline_text((column, row), text, font=font, fill=0, anchor = anchor)
|
||||||
|
#boundingBox = ImageDraw.textbbox(xy, text, font=None, anchor=None, spacing=4, align='left', direction=None, features=None, language=None, stroke_width=0, embedded_color=False, font_size=None)
|
||||||
|
boundingBox = context.multiline_textbbox((column,row),text,font=font,anchor=anchor)
|
||||||
|
print("boundingBox",boundingBox,"newrow",boundingBox[3])
|
||||||
|
return boundingBox[3]
|
||||||
|
|
||||||
# create an image
|
# create an image
|
||||||
displaysize = [800,480] # width, height - same as text writing features
|
displaysize = [800,480] # width, height - same as text writing features
|
||||||
row = 0 # current row to write at
|
row = 0 # current row to write at
|
||||||
out = Image.new("L", (displaysize[0], displaysize[1]),255)
|
out = Image.new("L", (displaysize[0], displaysize[1]),255)
|
||||||
|
|
||||||
# get a font
|
# get a font
|
||||||
fnt = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",25)
|
|
||||||
fntBold = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf",35)
|
|
||||||
HeightNormal = 25
|
HeightNormal = 25
|
||||||
HeightBold = 35
|
HeightBold = 35
|
||||||
MarginLeft = 1
|
MarginLeft = 1
|
||||||
@@ -23,29 +32,36 @@ d = ImageDraw.Draw(out)
|
|||||||
# create text
|
# create text
|
||||||
txt1 = datetime.datetime.now(pytz.timezone('America/New_York')).strftime('%A %B %d, %Y')
|
txt1 = datetime.datetime.now(pytz.timezone('America/New_York')).strftime('%A %B %d, %Y')
|
||||||
# draw multiline text
|
# draw multiline text
|
||||||
d.multiline_text((displaysize[0]/2, row), txt1, font=fntBold, fill=0, anchor = "ma") #, align="center")
|
#d.multiline_text((displaysize[0]/2, row), txt1, font=fntBigBold, fill=0, anchor = "ma") #, align="center")
|
||||||
row += HeightBold
|
row = WriteTextBlock(txt1,d,fntBigBold,displaysize[0]/2,row,"ma")
|
||||||
|
#row += HeightBold
|
||||||
|
|
||||||
txt1a = "As of "+datetime.datetime.now(pytz.timezone('America/New_York')).strftime('%I:%M %p')
|
txt1a = "As of "+datetime.datetime.now(pytz.timezone('America/New_York')).strftime('%I:%M %p')
|
||||||
d.multiline_text((displaysize[0]/2, row), txt1a, font=fnt, fill=0, anchor = "ma") #, align="center")
|
#d.multiline_text((displaysize[0]/2, row), txt1a, font=fnt, fill=0, anchor = "ma") #, align="center")
|
||||||
row += HeightNormal
|
row = WriteTextBlock(txt1a,d,fnt,displaysize[0]/2,row,"ma")
|
||||||
|
#row += HeightNormal
|
||||||
|
|
||||||
d.multiline_text((MarginLeft, row), "Weather:", font=fnt, fill=0, anchor = "la")
|
#d.multiline_text((MarginLeft, row), "Weather:", font=fnt, fill=0, anchor = "la")
|
||||||
row += HeightNormal
|
#row += HeightNormal
|
||||||
|
row = WriteTextBlock("Weather",d,fnt,MarginLeft,row,"la")
|
||||||
try:
|
try:
|
||||||
weather = google_weather.get_google_weather()
|
weather = "" #google_weather.get_google_weather()
|
||||||
txt2 = "Current: "+weather["current"] \
|
txt2 = "Current: "+weather["current"] \
|
||||||
+"\nToday's forecast: "+weather["forecast_today"] \
|
+"\nToday's forecast: "+weather["forecast_today"] \
|
||||||
+"\nTomorrow: "+weather["forecast_tomorrow"]
|
+"\nTomorrow: "+weather["forecast_tomorrow"]
|
||||||
except: # Assume the weather API blew up
|
except: # Assume the weather API blew up
|
||||||
txt2 = "Problem getting weather (from ImageGen)"
|
txt2 = "Problem getting weather (from ImageGen)"
|
||||||
d.multiline_text((MarginIndent, row), txt2, font=fnt, fill=0, anchor = "la")
|
row = WriteTextBlock(txt2,d,fnt,MarginIndent,row,"la")
|
||||||
row += 3*HeightNormal
|
#d.multiline_text((MarginIndent, row), txt2, font=fnt, fill=0, anchor = "la")
|
||||||
|
#row += 3*HeightNormal
|
||||||
|
|
||||||
d.multiline_text((MarginLeft,row), "Pirates:", font=fnt, fill=0, anchor = "la")
|
#d.multiline_text((MarginLeft,row), "Pirates:", font=fnt, fill=0, anchor = "la")
|
||||||
row += HeightNormal
|
#row += HeightNormal
|
||||||
d.multiline_text((MarginIndent,row), mlb.get_pirates(), font=fnt, fill=0, anchor = "la")
|
row = WriteTextBlock("Pirates",d,fnt,MarginLeft,row,"la")
|
||||||
row += 3*HeightNormal
|
#d.multiline_text((MarginIndent,row), mlb.get_pirates(), font=fnt, fill=0, anchor = "la")#
|
||||||
|
row = WriteTextBlock(mlb.get_pirates(),d,fnt,MarginIndent,row,"la")
|
||||||
|
##row += 3*HeightNormal
|
||||||
|
row = WriteTextBlock("========== End =========",d,fnt,MarginLeft,row,"la")
|
||||||
|
|
||||||
out.save("/mnt/nfs/HomeAutomation/ForHA.jpg","JPEG")
|
out.save("/mnt/nfs/HomeAutomation/ForHA.jpg","JPEG")
|
||||||
#out.show()
|
#out.show()
|
||||||
|
|||||||
Reference in New Issue
Block a user