Merge pull request #344 from aceinnolab/feature/#339
implement rotation for webshot module
This commit is contained in:
commit
e6ebbb293c
@ -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')
|
||||
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user