Mirror of https://github.com/Jxck-S/plane-notify
This is the backend to ElonsJet and other bots
acasads-badsbadsbexchangeadsbxairportemergency-squawklandopenskyopensky-apiopensky-networkplaneresolutionadviosrysquawktakeofftcas
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.0 KiB
69 lines
2.0 KiB
4 years ago
|
def append_airport(filename, airport):
|
||
4 years ago
|
from PIL import Image, ImageDraw, ImageFont
|
||
4 years ago
|
distance_mi = airport['distance_mi']
|
||
|
icao = airport['icao']
|
||
|
iata = airport['iata_code']
|
||
4 years ago
|
distance_km = distance_mi * 1.609
|
||
|
|
||
|
# create Image object with the input image
|
||
|
image = Image.open(filename)
|
||
|
# initialise the drawing context with
|
||
|
# the image object as background
|
||
|
draw = ImageDraw.Draw(image)
|
||
4 years ago
|
|
||
4 years ago
|
#Setup fonts
|
||
4 years ago
|
fontfile = "./dependencies/Roboto-Regular.ttf"
|
||
4 years ago
|
font = ImageFont.truetype(fontfile, 14)
|
||
|
mini_font = ImageFont.truetype(fontfile, 12)
|
||
|
head_font = ImageFont.truetype(fontfile, 16)
|
||
|
|
||
|
#Setup Colors
|
||
|
black = 'rgb(0, 0, 0)' # Black
|
||
|
white = 'rgb(255, 255, 255)' # White
|
||
|
navish = 'rgb(0, 63, 75)'
|
||
4 years ago
|
whitish = 'rgb(248, 248, 248)'
|
||
4 years ago
|
#Info Box
|
||
4 years ago
|
draw.rectangle(((325, 760), (624, 800)), fill= white, outline=black)
|
||
4 years ago
|
#Header Box
|
||
4 years ago
|
draw.rectangle(((401, 738), (549, 760)), fill= navish)
|
||
4 years ago
|
#ADSBX Logo
|
||
4 years ago
|
draw.rectangle(((658, 762), (800, 782)), fill= white)
|
||
|
adsbx = Image.open("./dependencies/ADSBX_Logo.png")
|
||
4 years ago
|
adsbx = adsbx.resize((25, 25), Image.ANTIALIAS)
|
||
|
image.paste(adsbx, (632, 757), adsbx)
|
||
4 years ago
|
#Create Text
|
||
4 years ago
|
#ADSBX Credit
|
||
|
(x, y) = (660, 760)
|
||
|
text = "adsbexchange.com"
|
||
|
draw.text((x, y), text, fill=black, font=head_font)
|
||
4 years ago
|
#Nearest Airport Header
|
||
4 years ago
|
(x, y) = (422, 740)
|
||
4 years ago
|
text = "Nearest Airport"
|
||
|
draw.text((x, y), text, fill=white, font=head_font)
|
||
4 years ago
|
#ICAO | IATA
|
||
4 years ago
|
(x, y) = (330, 765)
|
||
4 years ago
|
text = iata + " / " + icao
|
||
4 years ago
|
draw.text((x, y), text, fill=black, font=font)
|
||
|
#Distance
|
||
4 years ago
|
(x, y) = (460, 765)
|
||
4 years ago
|
text = str(round(distance_mi, 2)) + "mi / " + str(round(distance_km, 2)) + "km away"
|
||
|
draw.text((x, y), text, fill=black, font=font)
|
||
|
#Full name
|
||
4 years ago
|
(x, y) = (330, 783)
|
||
|
MAX_WIDTH = 325
|
||
|
if font.getsize(airport['name'])[0] <= MAX_WIDTH:
|
||
|
text = airport['name']
|
||
|
else:
|
||
|
text = ""
|
||
|
for char in airport['name']:
|
||
|
if font.getsize(text)[0] >= (MAX_WIDTH - 10):
|
||
|
text += "..."
|
||
|
break
|
||
|
else:
|
||
|
text += char
|
||
|
|
||
|
|
||
4 years ago
|
draw.text((x, y), text, fill=black, font=mini_font)
|
||
4 years ago
|
image.show()
|
||
4 years ago
|
# save the edited image
|
||
|
image.save(filename)
|