예제 #1
0
    def test_offset(self):
        # Arrange
        im = Image.open("Tests/images/imagedraw_ellipse_RGB.png")
        xoffset = 45
        yoffset = 20

        # Act
        new = ImageChops.offset(im, xoffset, yoffset)

        # Assert
        self.assertEqual(new.getbbox(), (0, 45, 100, 96))
        self.assertEqual(new.getpixel((50, 50)), BLACK)
        self.assertEqual(new.getpixel((50 + xoffset, 50 + yoffset)),
                         DARK_GREEN)

        # Test no yoffset
        self.assertEqual(ImageChops.offset(im, xoffset),
                         ImageChops.offset(im, xoffset, xoffset))
예제 #2
0
    def test_duplicate(self):
        # Arrange
        im = hopper()

        # Act
        new = ImageChops.duplicate(im)

        # Assert
        self.assert_image_equal(new, im)
예제 #3
0
    def test_add_modulo_no_clip(self):
        # Arrange
        im = hopper()

        # Act
        new = ImageChops.add_modulo(im, im)

        # Assert
        self.assertEqual(new.getpixel((50, 50)), (224, 76, 254))
예제 #4
0
    def test_lighter_pixel(self):
        # Arrange
        im1 = hopper()
        im2 = Image.open("Tests/images/imagedraw_chord_RGB.png")

        # Act
        new = ImageChops.lighter(im1, im2)

        # Assert
        self.assertEqual(new.getpixel((50, 50)), (255, 255, 127))
예제 #5
0
    def test_lighter_image(self):
        # Arrange
        im1 = Image.open("Tests/images/imagedraw_chord_RGB.png")
        im2 = Image.open("Tests/images/imagedraw_outline_chord_RGB.png")

        # Act
        new = ImageChops.lighter(im1, im2)

        # Assert
        self.assert_image_equal(new, im1)
예제 #6
0
    def test_subtract_modulo_no_clip(self):
        # Arrange
        im1 = hopper()
        im2 = Image.open("Tests/images/imagedraw_chord_RGB.png")

        # Act
        new = ImageChops.subtract_modulo(im1, im2)

        # Assert
        self.assertEqual(new.getpixel((50, 50)), (241, 167, 127))
예제 #7
0
    def test_difference_pixel(self):
        # Arrange
        im1 = hopper()
        im2 = Image.open("Tests/images/imagedraw_polygon_kite_RGB.png")

        # Act
        new = ImageChops.difference(im1, im2)

        # Assert
        self.assertEqual(new.getpixel((50, 50)), (240, 166, 128))
예제 #8
0
    def test_difference(self):
        # Arrange
        im1 = Image.open("Tests/images/imagedraw_arc_end_le_start.png")
        im2 = Image.open("Tests/images/imagedraw_arc_no_loops.png")

        # Act
        new = ImageChops.difference(im1, im2)

        # Assert
        self.assertEqual(new.getbbox(), (25, 25, 76, 76))
예제 #9
0
    def test_darker_pixel(self):
        # Arrange
        im1 = hopper()
        im2 = Image.open("Tests/images/imagedraw_chord_RGB.png")

        # Act
        new = ImageChops.darker(im1, im2)

        # Assert
        self.assertEqual(new.getpixel((50, 50)), (240, 166, 0))
예제 #10
0
    def test_constant(self):
        # Arrange
        im = Image.new("RGB", (20, 10))

        # Act
        new = ImageChops.constant(im, GREY)

        # Assert
        self.assertEqual(new.size, im.size)
        self.assertEqual(new.getpixel((0, 0)), GREY)
        self.assertEqual(new.getpixel((19, 9)), GREY)
예제 #11
0
    def test_invert(self):
        # Arrange
        im = Image.open("Tests/images/imagedraw_floodfill.png")

        # Act
        new = ImageChops.invert(im)

        # Assert
        self.assertEqual(new.getbbox(), (0, 0, 100, 100))
        self.assertEqual(new.getpixel((0, 0)), WHITE)
        self.assertEqual(new.getpixel((50, 50)), CYAN)
예제 #12
0
    def test_blend(self):
        # Arrange
        im1 = Image.open("Tests/images/imagedraw_ellipse_RGB.png")
        im2 = Image.open("Tests/images/imagedraw_floodfill.png")

        # Act
        new = ImageChops.blend(im1, im2, 0.5)

        # Assert
        self.assertEqual(new.getbbox(), (25, 25, 76, 76))
        self.assertEqual(new.getpixel((50, 50)), BROWN)
예제 #13
0
    def test_add_scale_offset(self):
        # Arrange
        im1 = Image.open("Tests/images/imagedraw_ellipse_RGB.png")
        im2 = Image.open("Tests/images/imagedraw_floodfill.png")

        # Act
        new = ImageChops.add(im1, im2, scale=2.5, offset=100)

        # Assert
        self.assertEqual(new.getbbox(), (0, 0, 100, 100))
        self.assertEqual(new.getpixel((50, 50)), (202, 151, 100))
예제 #14
0
    def test_add_modulo(self):
        # Arrange
        im1 = Image.open("Tests/images/imagedraw_ellipse_RGB.png")
        im2 = Image.open("Tests/images/imagedraw_floodfill.png")

        # Act
        new = ImageChops.add_modulo(im1, im2)

        # Assert
        self.assertEqual(new.getbbox(), (25, 25, 76, 76))
        self.assertEqual(new.getpixel((50, 50)), ORANGE)
예제 #15
0
    def test_subtract_scale_offset(self):
        # Arrange
        im1 = Image.open("Tests/images/imagedraw_chord_RGB.png")
        im2 = Image.open("Tests/images/imagedraw_outline_chord_RGB.png")

        # Act
        new = ImageChops.subtract(im1, im2, scale=2.5, offset=100)

        # Assert
        self.assertEqual(new.getbbox(), (0, 0, 100, 100))
        self.assertEqual(new.getpixel((50, 50)), (100, 202, 100))
예제 #16
0
    def test_multiply_black(self):
        """If you multiply an image with a solid black image,
        the result is black."""
        # Arrange
        im1 = hopper()
        black = Image.new("RGB", im1.size, "black")

        # Act
        new = ImageChops.multiply(im1, black)

        # Assert
        self.assert_image_equal(new, black)
예제 #17
0
    def test_subtract_modulo(self):
        # Arrange
        im1 = Image.open("Tests/images/imagedraw_chord_RGB.png")
        im2 = Image.open("Tests/images/imagedraw_outline_chord_RGB.png")

        # Act
        new = ImageChops.subtract_modulo(im1, im2)

        # Assert
        self.assertEqual(new.getbbox(), (25, 50, 76, 76))
        self.assertEqual(new.getpixel((50, 50)), GREEN)
        self.assertEqual(new.getpixel((50, 51)), BLACK)
예제 #18
0
    def test_multiply_green(self):
        # Arrange
        im = Image.open("Tests/images/imagedraw_floodfill.png")
        green = Image.new("RGB", im.size, "green")

        # Act
        new = ImageChops.multiply(im, green)

        # Assert
        self.assertEqual(new.getbbox(), (25, 25, 76, 76))
        self.assertEqual(new.getpixel((25, 25)), DARK_GREEN)
        self.assertEqual(new.getpixel((50, 50)), BLACK)
예제 #19
0
    def test_multiply_white(self):
        """If you multiply with a solid white image,
        the image is unaffected."""
        # Arrange
        im1 = hopper()
        white = Image.new("RGB", im1.size, "white")

        # Act
        new = ImageChops.multiply(im1, white)

        # Assert
        self.assert_image_equal(new, im1)
예제 #20
0
    def test_sanity(self):

        im = hopper("L")

        ImageChops.constant(im, 128)
        ImageChops.duplicate(im)
        ImageChops.invert(im)
        ImageChops.lighter(im, im)
        ImageChops.darker(im, im)
        ImageChops.difference(im, im)
        ImageChops.multiply(im, im)
        ImageChops.screen(im, im)

        ImageChops.add(im, im)
        ImageChops.add(im, im, 2.0)
        ImageChops.add(im, im, 2.0, 128)
        ImageChops.subtract(im, im)
        ImageChops.subtract(im, im, 2.0)
        ImageChops.subtract(im, im, 2.0, 128)

        ImageChops.add_modulo(im, im)
        ImageChops.subtract_modulo(im, im)

        ImageChops.blend(im, im, 0.5)
        ImageChops.composite(im, im, im)

        ImageChops.offset(im, 10)
        ImageChops.offset(im, 10, 20)