Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: properties for width-height of image #359

Merged
merged 11 commits into from
Jun 16, 2023
24 changes: 24 additions & 0 deletions src/safeds/data/image/containers/_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,30 @@ def format(self) -> ImageFormat:
"""
return self._format

@property
def width(self) -> int:
"""
Get the width of the image in pixels.

Returns
-------
width : int
The width of the image.
"""
return self._image.width

@property
def height(self) -> int:
"""
Get the height of the image in pixels.

Returns
-------
height : int
The height of the image.
"""
return self._image.height

# ------------------------------------------------------------------------------------------------------------------
# Conversion
# ------------------------------------------------------------------------------------------------------------------
Expand Down
22 changes: 22 additions & 0 deletions tests/safeds/data/image/containers/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,28 @@ def test_should_return_correct_format(self, image: Image, format_: ImageFormat)
assert image.format == format_


class TestProperties:
@pytest.mark.parametrize(
("image", "width", "height"),
[
(
Image.from_jpeg_file(resolve_resource_path("image/white_square.jpg")),
1,
1,
),
(
Image.from_png_file(resolve_resource_path("image/snapshot_boxplot.png")),
640,
480,
),
],
ids=["[1,1].jpg", "[640,480].png"],
)
def test_should_return_image_properties(self, image: Image, width: int, height: int) -> None:
assert image.width == width
assert image.height == height


class TestToJpegFile:
@pytest.mark.parametrize(
"path",
Expand Down