diff --git a/modules/inkycal_image.py b/modules/inkycal_image.py index 0840347..6ee4ab8 100644 --- a/modules/inkycal_image.py +++ b/modules/inkycal_image.py @@ -14,7 +14,9 @@ import numpy """----------------------------------------------------------------""" #path = 'https://github.com/aceisace/Inky-Calendar/raw/master/Gallery/Inky-Calendar-logo.png' -path ='/home/pi/Inky-Calendar/images/canvas.png' +#path ='/home/pi/Inky-Calendar/images/canvas.png' +path = inkycal_image_path +path_body = inkycal_image_path_body mode = 'auto' # 'horizontal' # 'vertical' # 'auto' upside_down = True # Flip image by 180 deg (upside-down) alignment = 'center' # top_center, top_left, center_left, bottom_right etc. @@ -22,10 +24,26 @@ colours = 'bwr' # bwr # bwy # bw render = True # show image on E-Paper? """----------------------------------------------------------------""" +# First determine dimensions +if mode == 'horizontal': + display_width, display_height == display_height, display_width + +if mode == 'vertical': + pass + +# .. Then substitute possibly parameterized path +# TODO Get (assigned) panel dimensions instead of display dimensions +path = path.replace('{model}', model).replace('{width}',str(display_width)).replace('{height}',str(display_height)) + """Try to open the image if it exists and is an image file""" try: if 'http' in path: - im = Image.open(requests.get(path, stream=True).raw) + if path_body is None: + # Plain GET + im = Image.open(requests.get(path, stream=True).raw) + else: + # POST request, passing path_body in the body + im = Image.open(requests.post(path, json=path_body, stream=True).raw) else: im = Image.open(path) except FileNotFoundError: @@ -39,12 +57,6 @@ except OSError: if upside_down == True: im.rotate(180, expand = True) -if mode == 'horizontal': - display_width, display_height == display_height, display_width - -if mode == 'vertical': - pass - if mode == 'auto': if (im.width > im.height) and (display_width < display_height): print('display vertical, image horizontal -> flipping image') diff --git a/settings/settings.py b/settings/settings.py index 9ce7610..5b46cf3 100644 --- a/settings/settings.py +++ b/settings/settings.py @@ -23,6 +23,38 @@ bottom_section = "inkycal_rss" # "inkycal_rss" # URLs should have this sign (") on both side -> "url1" # If more than one URL is used, separate each one with a comma -> "url1", "url2" +######################## +# inkycal_image config: +# +# inkycal_image_path +# The url or file path to obtain the image from. +# The following parameters within accolades ({}) will be substituted: +# - model +# - width +# - height +# +# Samples : +# The inkycal logo: +# inkycal_image_path = 'https://github.com/aceisace/Inky-Calendar/raw/master/Gallery/Inky-Calendar-logo.png' +# +# A dynamic image with a demo-calendar +# inkycal_image_path = 'https://inkycal.robertsirre.nl/panel/test/{model}/image?width={width}&height={height}' +# +# Dynamic image with configurable calendars (see https://inkycal.robertsirre.nl/ and parameter inkycal_image_path_body) +# inkycal_image_path = 'https://inkycal.robertsirre.nl/panel/calendar/{model}?width={width}&height={height}' + +inkycal_image_path ='/home/pi/Inky-Calendar/images/canvas.png' + +# Optional: inkycal_image_path_body +# Allows obtaining complexer configure images. +# When inkycal_image_path starts with `http` and inkycal_image_path_body is specified, the image is obtained using POST instead of GET. +# NOTE: structure of the body depends on the web-based image service +# inkycal_image_path_body = [ +# 'https://calendar.google.com/calendar/ical/en.usa%23holiday%40group.v.calendar.google.com/public/basic.ics', +# 'https://www.calendarlabs.com/ical-calendar/ics/101/Netherlands_Holidays.ics' +# ] +######################## + """Supported E-Paper models""" # epd_7_in_5_v2_colour # 7.5" high-res black-white-red/yellow # epd_7_in_5_v2 # 7.5" high-res black-white