diff --git a/src/safeds/data/image/containers/_image.py b/src/safeds/data/image/containers/_image.py index d122d06c8..4649b3e0b 100644 --- a/src/safeds/data/image/containers/_image.py +++ b/src/safeds/data/image/containers/_image.py @@ -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 # ------------------------------------------------------------------------------------------------------------------ diff --git a/tests/safeds/data/image/containers/test_image.py b/tests/safeds/data/image/containers/test_image.py index e4b0a87c9..29164d27f 100644 --- a/tests/safeds/data/image/containers/test_image.py +++ b/tests/safeds/data/image/containers/test_image.py @@ -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",