Skip to content

Commit

Permalink
issue #74: added variable maintain_aspect_ratio to Image
Browse files Browse the repository at this point in the history
  • Loading branch information
SibrenJacobs committed May 30, 2022
1 parent 97c1d40 commit 0bb4b08
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
33 changes: 28 additions & 5 deletions cloudofficeprint/elements/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ def __init__(self,
transparency: Union[int, str]=None,
url: str=None,
width: Union[int, str]=None,
height: Union[int, str]=None):
height: Union[int, str]=None,
maintain_aspect_ratio: bool=None
):
"""
Args:
name (str): The name of the image element.
Expand All @@ -35,6 +37,8 @@ def __init__(self,
url (str): The URL to load when the image is clicked.
width (Union[int, str]): The width of the image (for non-proportional scaling).
height (Union[int, str]): The height of the image (for non-proportional scaling).
maintain_aspect_ratio (bool): Whether to remain the aspect ratio.
Cloud Office Print server expects width to be specified for this option to work.
"""
super().__init__(name)
self.source: str = source
Expand All @@ -47,6 +51,7 @@ def __init__(self,
self.url: str = url
self.width: Union[int, str] = width
self.height: Union[int, str] = height
self.maintain_aspect_ratio: bool = maintain_aspect_ratio

@property
def alt_text(self) -> str:
Expand Down Expand Up @@ -133,6 +138,8 @@ def _dict_suffixes(self) -> Dict:
result["_width"] = self.width
if self.height is not None:
result["_height"] = self.height
if self.maintain_aspect_ratio is not None:
result["_maintain_aspect_ratio"] = self.maintain_aspect_ratio

return result

Expand All @@ -158,7 +165,8 @@ def from_file(
transparency: Union[int, str]=None,
url: str=None,
width: Union[int, str]=None,
height: Union[int, str]=None
height: Union[int, str]=None,
maintain_aspect_ratio: bool=None
) -> 'Image':
"""Generate an Image object from a local file.
Expand All @@ -179,6 +187,8 @@ def from_file(
url (str): The URL to load when the image is clicked.
width (Union[int, str]): The width of the image (for non-proportional scaling).
height (Union[int, str]): The height of the image (for non-proportional scaling).
maintain_aspect_ratio (bool): Whether to remain the aspect ratio.
Cloud Office Print server expects width to be specified for this option to work.
Returns:
Image: the generated Image object from a local file
Expand All @@ -195,6 +205,7 @@ def from_file(
url,
width,
height,
maintain_aspect_ratio,
)

@staticmethod
Expand All @@ -209,7 +220,8 @@ def from_raw(
transparency: Union[int, str]=None,
url: str=None,
width: Union[int, str]=None,
height: Union[int, str]=None
height: Union[int, str]=None,
maintain_aspect_ratio: bool=None
) -> 'Image':
"""Generate an Image object from raw data.
Expand All @@ -230,6 +242,8 @@ def from_raw(
url (str): The URL to load when the image is clicked.
width (Union[int, str]): The width of the image (for non-proportional scaling).
height (Union[int, str]): The height of the image (for non-proportional scaling).
maintain_aspect_ratio (bool): Whether to remain the aspect ratio.
Cloud Office Print server expects width to be specified for this option to work.
Returns:
Image: the generated Image object from raw data
Expand All @@ -246,6 +260,7 @@ def from_raw(
url,
width,
height,
maintain_aspect_ratio,
)

@staticmethod
Expand All @@ -260,7 +275,8 @@ def from_base64(
transparency: Union[int, str]=None,
url: str=None,
width: Union[int, str]=None,
height: Union[int, str]=None
height: Union[int, str]=None,
maintain_aspect_ratio: bool=None
) -> 'Image':
"""Generate an Image object from a base64 string.
Expand All @@ -281,6 +297,8 @@ def from_base64(
url (str): The URL to load when the image is clicked.
width (Union[int, str]): The width of the image (for non-proportional scaling).
height (Union[int, str]): The height of the image (for non-proportional scaling).
maintain_aspect_ratio (bool): Whether to remain the aspect ratio.
Cloud Office Print server expects width to be specified for this option to work.
Returns:
Image: the generated Image object from a base64 string
Expand All @@ -297,6 +315,7 @@ def from_base64(
url,
width,
height,
maintain_aspect_ratio,
)

@staticmethod
Expand All @@ -311,7 +330,8 @@ def from_url(
transparency: Union[int, str]=None,
url: str=None,
width: Union[int, str]=None,
height: Union[int, str]=None
height: Union[int, str]=None,
maintain_aspect_ratio: bool=None
) -> 'Image':
"""Generate an Image object from a URL.
Expand All @@ -332,6 +352,8 @@ def from_url(
url (str): The URL to load when the image is clicked.
width (Union[int, str]): The width of the image (for non-proportional scaling).
height (Union[int, str]): The height of the image (for non-proportional scaling).
maintain_aspect_ratio (bool): Whether to remain the aspect ratio.
Cloud Office Print server expects width to be specified for this option to work.
Returns:
Image: the generated Image object from a URL
Expand All @@ -348,4 +370,5 @@ def from_url(
url,
width,
height,
maintain_aspect_ratio,
)
6 changes: 4 additions & 2 deletions tests/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ def test_image():
transparency=50,
url='url',
width=30,
height=25
height=25,
maintain_aspect_ratio=True,
)
image_expected = {
'image1': 'url_source',
Expand All @@ -25,7 +26,8 @@ def test_image():
'image1_transparency': 50,
'image1_url': 'url',
'image1_width': 30,
'image1_height': 25
'image1_height': 25,
'image1_maintain_aspect_ratio': True
}
assert image.as_dict == image_expected

Expand Down

0 comments on commit 0bb4b08

Please sign in to comment.