Exemple #1
0
    def test_auto_orient_rotates_asset_correctly(self, processor, exif_orientation, image_transpositions):
        reference_asset = get_jpeg_image_asset()
        misoriented_asset = get_jpeg_image_asset(transpositions=image_transpositions,
                                                 exif={'orientation': exif_orientation})
        auto_orient_operator = processor.auto_orient()

        oriented_asset = auto_orient_operator(misoriented_asset)

        with PIL.Image.open(reference_asset.essence) as reference_image, \
                PIL.Image.open(oriented_asset.essence) as oriented_image:
            assert is_equal_in_black_white_space(reference_image, oriented_image)
Exemple #2
0
    def test_transpose_flips_dimensions(self, processor):
        asset = get_jpeg_image_asset()
        transpose_operator = processor.transpose()

        transposed_asset = transpose_operator(asset)

        assert asset.width == transposed_asset.height and asset.height == transposed_asset.width
Exemple #3
0
    def test_transpose_keeps_original_mime_type(self, processor):
        asset = get_jpeg_image_asset()
        transpose_operator = processor.transpose()

        transposed_asset = transpose_operator(asset)

        assert transposed_asset.mime_type == asset.mime_type
Exemple #4
0
    def test_resize_in_fill_mode_preserves_aspect_ratio_for_portrait_image(self, processor, width, height):
        jpeg_image_asset_portrait = get_jpeg_image_asset(width=width, height=height)
        resize_operator = processor.resize(width=9, height=10, mode=madam.image.ResizeMode.FILL)

        resized_asset = resize_operator(jpeg_image_asset_portrait)

        assert resized_asset.width == 9
        assert resized_asset.height == 15
Exemple #5
0
    def test_resize_in_fit_mode_preserves_aspect_ratio_for_landscape_image(self, processor, width, height):
        jpeg_image_asset_landscape = get_jpeg_image_asset(width=width, height=height)
        resize_operator = processor.resize(width=9, height=10, mode=madam.image.ResizeMode.FIT)

        resized_asset = resize_operator(jpeg_image_asset_landscape)

        assert resized_asset.width == 9
        assert resized_asset.height == 7
Exemple #6
0
    def test_convert_creates_new_asset(self, processor):
        asset = get_jpeg_image_asset()
        conversion_operator = processor.convert(mime_type='image/png')

        converted_asset = conversion_operator(asset)

        assert isinstance(converted_asset, madam.core.Asset)
        assert converted_asset != asset
Exemple #7
0
    def test_transpose_is_reversible(self, processor):
        asset = get_jpeg_image_asset()
        transpose_operator = processor.transpose()

        transposed_asset = transpose_operator(transpose_operator(asset))

        with PIL.Image.open(transposed_asset.essence) as transposed_image, \
                PIL.Image.open(asset.essence) as image:
            assert is_equal_in_black_white_space(transposed_image, image)
Exemple #8
0
    def test_flip_is_reversible(self, processor, orientation):
        asset = get_jpeg_image_asset()
        flip_operator = processor.flip(orientation=orientation)

        flipped_asset = flip_operator(flip_operator(asset))

        with PIL.Image.open(flipped_asset.essence) as flipped_image, \
                PIL.Image.open(asset.essence) as image:
            assert is_equal_in_black_white_space(flipped_image, image)
Exemple #9
0
    def test_read_jpeg_does_not_alter_the_original_file(self, manager):
        jpeg_data = get_jpeg_image_asset().essence
        original_image_data = jpeg_data.read()
        jpeg_data.seek(0)

        manager.read(jpeg_data)

        jpeg_data.seek(0)
        image_data_after_reading = jpeg_data.read()
        assert original_image_data == image_data_after_reading