Skip to content

Commit

Permalink
feat: 290 properties for width-height of image (#359)
Browse files Browse the repository at this point in the history
Closes #290

### Summary of Changes

* feat: Properties for width and height of an image should be returned
in pixels.

---------

Co-authored-by: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com>
  • Loading branch information
jxnior01 and megalinter-bot committed Jun 16, 2023
1 parent 3a971ca commit d9ebdc1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
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

0 comments on commit d9ebdc1

Please sign in to comment.