finally got the hang of bw/colour image handling
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
Inkycal Image Module
|
||||
Copyright by aceinnolab
|
||||
"""
|
||||
|
||||
from inkycal.custom import *
|
||||
from inkycal.modules.inky_image import image_to_palette
|
||||
from inkycal.modules.inky_image import Inkyimage as Images
|
||||
from inkycal.modules.template import inkycal_module
|
||||
|
||||
@@ -11,36 +11,21 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Inkyimage(inkycal_module):
|
||||
"""Displays an image from URL or local path
|
||||
"""
|
||||
"""Displays an image from URL or local path"""
|
||||
|
||||
name = "Inkycal Image - show an image from a URL or local path"
|
||||
|
||||
requires = {
|
||||
|
||||
"path": {
|
||||
"label": "Path to a local folder, e.g. /home/pi/Desktop/images. "
|
||||
"Only PNG and JPG/JPEG images are used for the slideshow."
|
||||
"Only PNG and JPG/JPEG images are used for the slideshow."
|
||||
},
|
||||
|
||||
"palette": {
|
||||
"label": "Which palette should be used for converting images?",
|
||||
"options": ["bw", "bwr", "bwy"]
|
||||
}
|
||||
|
||||
"palette": {"label": "Which palette should be used for converting images?", "options": ["bw", "bwr", "bwy"]},
|
||||
}
|
||||
|
||||
optional = {
|
||||
|
||||
"autoflip": {
|
||||
"label": "Should the image be flipped automatically?",
|
||||
"options": [True, False]
|
||||
},
|
||||
|
||||
"orientation": {
|
||||
"label": "Please select the desired orientation",
|
||||
"options": ["vertical", "horizontal"]
|
||||
}
|
||||
"autoflip": {"label": "Should the image be flipped automatically?", "options": [True, False]},
|
||||
"orientation": {"label": "Please select the desired orientation", "options": ["vertical", "horizontal"]},
|
||||
}
|
||||
|
||||
def __init__(self, config):
|
||||
@@ -48,24 +33,24 @@ class Inkyimage(inkycal_module):
|
||||
|
||||
super().__init__(config)
|
||||
|
||||
config = config['config']
|
||||
config = config["config"]
|
||||
|
||||
# required parameters
|
||||
for param in self.requires:
|
||||
if not param in config:
|
||||
raise Exception(f'config is missing {param}')
|
||||
raise Exception(f"config is missing {param}")
|
||||
|
||||
# optional parameters
|
||||
self.path = config['path']
|
||||
self.palette = config['palette']
|
||||
self.autoflip = config['autoflip']
|
||||
self.orientation = config['orientation']
|
||||
self.path = config["path"]
|
||||
self.palette = config["palette"]
|
||||
self.autoflip = config["autoflip"]
|
||||
self.orientation = config["orientation"]
|
||||
self.dither = True
|
||||
if 'dither' in config and config["dither"] == False:
|
||||
if "dither" in config and config["dither"] == False:
|
||||
self.dither = False
|
||||
|
||||
# give an OK message
|
||||
print(f'{__name__} loaded')
|
||||
print(f"{__name__} loaded")
|
||||
|
||||
def generate_image(self):
|
||||
"""Generate image for this module"""
|
||||
@@ -75,7 +60,7 @@ class Inkyimage(inkycal_module):
|
||||
im_height = int(self.height - (2 * self.padding_top))
|
||||
im_size = im_width, im_height
|
||||
|
||||
logger.info(f'Image size: {im_size}')
|
||||
logger.info(f"Image size: {im_size}")
|
||||
|
||||
# initialize custom image class
|
||||
im = Images()
|
||||
@@ -94,7 +79,7 @@ class Inkyimage(inkycal_module):
|
||||
im.resize(width=im_width, height=im_height)
|
||||
|
||||
# convert images according to specified palette
|
||||
im_black, im_colour = im.to_palette(self.palette, self.dither)
|
||||
im_black, im_colour = image_to_palette(image=im, palette=self.palette, dither=self.dither)
|
||||
|
||||
# with the images now send, clear the current image
|
||||
im.clear()
|
||||
@@ -103,5 +88,5 @@ class Inkyimage(inkycal_module):
|
||||
return im_black, im_colour
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(f'running {__name__} in standalone/debug mode')
|
||||
if __name__ == "__main__":
|
||||
print(f"running {__name__} in standalone/debug mode")
|
||||
|
Reference in New Issue
Block a user