From f03bb101259d86405a9c43d882f147273fa32a72 Mon Sep 17 00:00:00 2001 From: markjfine Date: Tue, 30 Mar 2021 07:07:38 -0400 Subject: [PATCH] Consistent traffic timestamp sizing Made timestamp appear to be the same size as the weather map. --- nrsc5-dui.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/nrsc5-dui.py b/nrsc5-dui.py index 49133f2..3ccbdb9 100644 --- a/nrsc5-dui.py +++ b/nrsc5-dui.py @@ -893,10 +893,14 @@ class NRSC5_DUI(object): os.remove(tileFile) # delete tile image # now put a timestamp on it. - imgMap = imgMap.convert("RGBA") - posTS = (imgMap.size[0]-235, imgMap.size[1]-29) # calculate position to put timestamp (bottom right) - imgTS = self.mkTimestamp(t, imgMap.size, posTS) # create timestamp - imgMap = Image.alpha_composite(imgMap, imgTS) # overlay timestamp + imgMap = imgMap.convert("RGBA") + imgBig = (981,981) # size of a weather map + #posTS = (imgMap.size[0]-235, imgMap.size[1]-29) # calculate position to put timestamp (bottom right) + posTS = (imgBig[0]-235, imgBig[1]-29) # calculate position to put timestamp (bottom right) + #imgTS = self.mkTimestamp(t, imgMap.size, posTS) # create timestamp + imgTS = self.mkTimestamp(t, imgBig, posTS) # create timestamp for a weather map + imgTS = imgTS.resize((imgMap.size[0], imgMap.size[1]), Image.LANCZOS) # resize it so it's proportional to the size of a traffic map (981 -> 600) + imgMap = Image.alpha_composite(imgMap, imgTS) # overlay timestamp on traffic map imgMap.save(os.path.join(mapDir, "TrafficMap.png")) # save traffic map @@ -1090,7 +1094,7 @@ class NRSC5_DUI(object): text = "{:04g}-{:02g}-{:02g} {:02g}:{:02g}".format(t.year, t.month, t.day, t.hour, t.minute) # format timestamp imgTS = Image.new("RGBA", size, (0,0,0,0)) # create a blank image draw = ImageDraw.Draw(imgTS) # the drawing object - font = ImageFont.truetype(os.path.join(resDir,"DejaVuSansMono.ttf"), 24) # DejaVu Sans Mono 24pt font + font = ImageFont.truetype(os.path.join(resDir,"DejaVuSansMono.ttf"), 24) # DejaVu Sans Mono 24pt font draw.rectangle((x,y, x+231,y+25), outline="black", fill=(128,128,128,96)) # draw a box around the text draw.text((x+3,y), text, fill="black", font=font) # draw the text return imgTS # return the image