From bf9f7db5acdadfcb25ac269bc04686828d0c98ac Mon Sep 17 00:00:00 2001 From: Ace Date: Thu, 20 Jun 2024 22:31:17 +0200 Subject: [PATCH] implement rotation for webshot module --- inkycal/modules/inkycal_webshot.py | 31 +++++++++++++++---- tests/test_inkycal_webshot.py | 49 ++++++++++++++++-------------- 2 files changed, 51 insertions(+), 29 deletions(-) diff --git a/inkycal/modules/inkycal_webshot.py b/inkycal/modules/inkycal_webshot.py index 8d08cc6..50b7fb0 100644 --- a/inkycal/modules/inkycal_webshot.py +++ b/inkycal/modules/inkycal_webshot.py @@ -41,7 +41,10 @@ class Webshot(inkycal_module): }, "crop_h": { "label": "Please enter the crop height", - } + }, + "rotation": { + "label": "Please enter the rotation. Must be either 0, 90, 180 or 270", + }, } def __init__(self, config): @@ -73,6 +76,12 @@ class Webshot(inkycal_module): else: self.crop_y = 0 + self.rotation = 0 + if "rotation" in config: + self.rotation = int(config["rotation"]) + if self.rotation not in [0, 90, 180, 270]: + raise Exception("Rotation must be either 0, 90, 180 or 270") + # give an OK message print(f'Inkycal webshot loaded') @@ -105,7 +114,7 @@ class Webshot(inkycal_module): logger.info( f'preparing webshot from {self.url}... cropH{self.crop_h} cropW{self.crop_w} cropX{self.crop_x} cropY{self.crop_y}') - shot = WebShot() + shot = WebShot(size=(im_height, im_width)) shot.params = { "--crop-x": self.crop_x, @@ -151,11 +160,21 @@ class Webshot(inkycal_module): centerPosX = int((im_width / 2) - (im.image.width / 2)) - webshotSpaceBlack.paste(im_webshot_black, (centerPosX, webshotCenterPosY)) - im_black.paste(webshotSpaceBlack) - webshotSpaceColour.paste(im_webshot_colour, (centerPosX, webshotCenterPosY)) - im_colour.paste(webshotSpaceColour) + if self.rotation != 0: + webshotSpaceBlack.paste(im_webshot_black, (centerPosX, webshotCenterPosY)) + im_black.paste(webshotSpaceBlack) + im_black = im_black.rotate(self.rotation, expand=True) + + webshotSpaceColour.paste(im_webshot_colour, (centerPosX, webshotCenterPosY)) + im_colour.paste(webshotSpaceColour) + im_colour = im_colour.rotate(self.rotation, expand=True) + else: + webshotSpaceBlack.paste(im_webshot_black, (centerPosX, webshotCenterPosY)) + im_black.paste(webshotSpaceBlack) + + webshotSpaceColour.paste(im_webshot_colour, (centerPosX, webshotCenterPosY)) + im_colour.paste(webshotSpaceColour) im.clear() logger.info(f'added webshot image') diff --git a/tests/test_inkycal_webshot.py b/tests/test_inkycal_webshot.py index 7105a12..d8e1b12 100755 --- a/tests/test_inkycal_webshot.py +++ b/tests/test_inkycal_webshot.py @@ -11,33 +11,13 @@ logger = logging.getLogger(__name__) logging.basicConfig(level=logging.DEBUG) tests = [ - { - "position": 1, - "name": "Webshot", - "config": { - "size": [400, 100], - "url": "https://github.com", - "palette": "bwr", - "padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en" - } - }, { "position": 1, "name": "Webshot", "config": { "size": [400, 200], - "url": "https://github.com", - "palette": "bwy", - "padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en" - } - }, - { - "position": 1, - "name": "Webshot", - "config": { - "size": [400, 300], - "url": "https://github.com", - "palette": "bw", + "url": "https://aceinnolab.com", + "palette": "bwr", "padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en" } }, @@ -46,8 +26,31 @@ tests = [ "name": "Webshot", "config": { "size": [400, 400], - "url": "https://github.com", + "url": "https://aceinnolab.com", + "palette": "bwy", + "rotation": 0, + "padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en" + } + }, + { + "position": 1, + "name": "Webshot", + "config": { + "size": [400, 600], + "url": "https://aceinnolab.com", + "palette": "bw", + "rotation": 90, + "padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en" + } + }, + { + "position": 1, + "name": "Webshot", + "config": { + "size": [400, 800], + "url": "https://aceinnolab.com", "palette": "bwr", + "rotation": 180, "padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en" } }