Merge pull request #344 from aceinnolab/feature/#339

implement rotation for webshot module
This commit is contained in:
Ace 2024-06-21 12:02:17 +02:00 committed by GitHub
commit e6ebbb293c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 51 additions and 29 deletions

View File

@ -41,7 +41,10 @@ class Webshot(inkycal_module):
}, },
"crop_h": { "crop_h": {
"label": "Please enter the crop height", "label": "Please enter the crop height",
} },
"rotation": {
"label": "Please enter the rotation. Must be either 0, 90, 180 or 270",
},
} }
def __init__(self, config): def __init__(self, config):
@ -73,6 +76,12 @@ class Webshot(inkycal_module):
else: else:
self.crop_y = 0 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 # give an OK message
print(f'Inkycal webshot loaded') print(f'Inkycal webshot loaded')
@ -105,7 +114,7 @@ class Webshot(inkycal_module):
logger.info( logger.info(
f'preparing webshot from {self.url}... cropH{self.crop_h} cropW{self.crop_w} cropX{self.crop_x} cropY{self.crop_y}') 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 = { shot.params = {
"--crop-x": self.crop_x, "--crop-x": self.crop_x,
@ -151,11 +160,21 @@ class Webshot(inkycal_module):
centerPosX = int((im_width / 2) - (im.image.width / 2)) 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)) if self.rotation != 0:
im_colour.paste(webshotSpaceColour) 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() im.clear()
logger.info(f'added webshot image') logger.info(f'added webshot image')

View File

@ -11,33 +11,13 @@ logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
tests = [ 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, "position": 1,
"name": "Webshot", "name": "Webshot",
"config": { "config": {
"size": [400, 200], "size": [400, 200],
"url": "https://github.com", "url": "https://aceinnolab.com",
"palette": "bwy", "palette": "bwr",
"padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en"
}
},
{
"position": 1,
"name": "Webshot",
"config": {
"size": [400, 300],
"url": "https://github.com",
"palette": "bw",
"padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en" "padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en"
} }
}, },
@ -46,8 +26,31 @@ tests = [
"name": "Webshot", "name": "Webshot",
"config": { "config": {
"size": [400, 400], "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", "palette": "bwr",
"rotation": 180,
"padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en" "padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en"
} }
} }