Inverted color and added sat images

This commit is contained in:
Sebastian 2018-12-24 13:00:26 +01:00
parent 13d6e94dba
commit 4bd3e45665
1 changed files with 41 additions and 12 deletions

View File

@ -12,7 +12,28 @@ from io import BytesIO
FONT_SIZE = 40
TEXT_COLOR = (0, 0, 0)
TEXT_COLOR = (255, 255, 255, 255)
def invert_back_white(img):
pixels = img.load()
for y in range(img.size[1]):
for x in range(img.size[0]):
r,g,b, _ = pixels[x,y]
if abs(r - g) < 5 and abs(r - g) < 5 and abs(b - g) < 5:
pixels[x,y] = (255 - r, 255 - g, 255 - b, 255)
def scale_to_height(img, new_height):
width, height = img.size
new_width = int(new_height * width / height)
return img.resize((new_width, new_height), Image.ANTIALIAS)
def scale_to_width(img, new_width):
width, height = img.size
new_height = int(new_width * height / width)
return img.resize((new_width, new_height), Image.ANTIALIAS)
def main():
now = datetime.now(pytz.utc)
@ -34,33 +55,41 @@ def main():
resp = requests.get('https://db.satnogs.org/api/satellites/%s/' % ob['norad_cat_id'])
sat_name = resp.json()['name']
sat_img_url = resp.json()['image']
resp = requests.get(ob['waterfall'])
waterfall = Image.open(BytesIO(resp.content))
waterfall = Image.open(BytesIO(resp.content)).convert('RGBA')
invert_back_white(waterfall)
width, height = waterfall.size
new_height = 1024
new_width = int(new_height * width / height)
waterfall = scale_to_height(waterfall, 1024)
water_width, _ = waterfall.size
waterfall = waterfall.resize((new_width, new_height), Image.ANTIALIAS)
logo = Image.open("satnogs-logo.png").convert(waterfall.mode)
logo = Image.open("satnogs-logo.png").convert('RGBA')
logo_w, logo_h = logo.size
invert_back_white(logo)
img = Image.new(waterfall.mode, (1280,1024))
sat_img = None
if sat_img_url != None:
resp = requests.get(sat_img_url)
sat_img = Image.open(BytesIO(resp.content)).convert('RGBA')
sat_img = scale_to_width(sat_img, 500)
img = Image.new('RGBA', (1280,1024))
draw = ImageDraw.Draw(img)
draw.rectangle((0, 0, 1280, 1024), fill=(255, 255, 255, 255))
draw.rectangle((0, 0, 1280, 1024), fill=(0, 0, 0, 255))
infos = "Satellite: %s\nStation: %s\nStart: %s\nEnd: %s" % (sat_name, ob['station_name'], ob['start'], ob['end'])
font = ImageFont.truetype("Montserrat-Regular.otf", FONT_SIZE)
draw.text((new_width + 100, logo_h+50),
draw.text((water_width + 100, logo_h+50),
infos,
TEXT_COLOR,
font=font)
img.paste(waterfall, (0, 0))
img.paste(logo, (new_width + 100, 20))
img.paste(logo, (water_width + 100, 20))
if sat_img != None:
img.paste(sat_img, (water_width + 100, 400))
img.save('waterfall_tmp.png')
os.rename('waterfall_tmp.png', 'waterfall.png')