implement rotation for webshot module

This commit is contained in:
Ace
2024-06-20 22:31:17 +02:00
parent eec1d1d627
commit bf9f7db5ac
2 changed files with 51 additions and 29 deletions

View File

@@ -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')