예제 #1
0
    def test_wider_image_gets_cropped_to_ratio(self):
        i = Image.new('RGB', (200, 100), BLACK)
        f = Formatter(i, self.format)

        i, crop_box = f.format()
        tools.assert_equals((50, 0, 150, 100), crop_box)
        tools.assert_equals((100, 100), i.size)
예제 #2
0
    def test_bigger_image_gets_shrinked_without_cropping(self):
        i = Image.new('RGB', (200, 200), BLACK)
        f = Formatter(i, self.format)

        i, crop_box = f.format()
        tools.assert_equals(None, crop_box)
        tools.assert_equals((100, 100), i.size)
예제 #3
0
파일: test_resize.py 프로젝트: skada/ella
    def test_taller_image_gets_cropped_to_ratio(self):
        i = Image.new('RGB', (100, 200), "black")
        f = Formatter(i, self.format)

        i, crop_box = f.format()
        tools.assert_equals((0, 50, 100, 150), crop_box)
        tools.assert_equals((100, 100), i.size)
예제 #4
0
    def test_smaller_image_remains_untouched(self):
        i = Image.new('RGB', (100, 20), BLACK)
        f = Formatter(i, self.format)

        i, crop_box = f.format()
        tools.assert_equals(None, crop_box)
        tools.assert_equals((100, 20), i.size)
예제 #5
0
    def test_wider_image_gets_shrinked_to_ratio_with_nocrop(self):
        i = Image.new('RGB', (200, 100), BLACK)
        self.format.nocrop = True
        f = Formatter(i, self.format)

        i, crop_box = f.format()
        tools.assert_equals(None, crop_box)
        tools.assert_equals((100, 50), i.size)
예제 #6
0
    def test_smaller_image_stretches_with_ratio_intact_with_stretch(self):
        i = Image.new('RGB', (20, 10), BLACK)
        self.format.stretch = True
        f = Formatter(i, self.format)

        i, crop_box = f.format()
        tools.assert_equals(None, crop_box)
        tools.assert_equals((100, 50), i.size)
예제 #7
0
    def test_flexible_height_doesnt_raise_exception_no_max_height(self):
        i = Image.new('RGB', (200, 100), BLACK)
        self.format.flexible_max_height = None
        self.format.flexible_height = True
        f = Formatter(i, self.format)

        i, crop_box = f.format()
        tools.assert_equals((100, 100), i.size)
예제 #8
0
    def test_taller_image_gets_shrinked_to_ratio_with_nocrop(self):
        i = Image.new('RGB', (100, 200), "black")
        self.format.nocrop = True
        f = Formatter(i, self.format)

        i, crop_box = f.format()
        self.assert_equals(None, crop_box)
        self.assert_equals((50, 100), i.size)
예제 #9
0
    def test_important_box_is_used_for_other_positive_x_motion_as_well(self):
        i = Image.new('RGB', (200, 100), "red")
        f = Formatter(i, self.format, important_box=(100,0,200,100))
        i.putpixel((100, 0), 0)

        i, crop_box = f.format()
        self.assert_equals((100,0,200,100), crop_box)
        self.assert_equals((100, 100), i.size)
        self.assert_equals((0,0,0), i.getpixel((0,0)))
예제 #10
0
    def test_important_box_is_used(self):
        i = Image.new('RGB', (200, 100), RED)
        f = Formatter(i, self.format, important_box=(0, 0, 100, 100))
        i.putpixel((99, 99), BLACK)

        i, crop_box = f.format()
        tools.assert_equals((0, 0, 100, 100), crop_box)
        tools.assert_equals((100, 100), i.size)
        tools.assert_equals(BLACK, i.getpixel((99, 99)))
예제 #11
0
    def test_flexible_height_saves_taller_images(self):
        i = Image.new('RGB', (100, 200), BLACK)
        self.format.flexible_max_height = 200
        self.format.flexible_height = True
        f = Formatter(i, self.format)

        i, crop_box = f.format()
        tools.assert_equals(None, crop_box)
        tools.assert_equals((100, 200), i.size)
예제 #12
0
파일: test_resize.py 프로젝트: skada/ella
    def test_custom_crop_box_is_used(self):
        i = Image.new('RGB', (200, 200), "red")
        f = Formatter(i, self.format, crop_box=(0, 0, 100, 100))
        i.putpixel((99, 99), 0)

        i, crop_box = f.format()
        tools.assert_equals((0, 0, 100, 100), crop_box)
        tools.assert_equals((100, 100), i.size)
        tools.assert_equals((0, 0, 0), i.getpixel((99, 99)))
예제 #13
0
    def test_important_box_is_used_for_positive_y_motion_as_well(self):
        i = Image.new('RGB', (100, 200), RED)
        f = Formatter(i, self.format, important_box=(0, 100, 100, 200))
        i.putpixel((0, 100), BLACK)

        i, crop_box = f.format()
        tools.assert_equals((0, 100, 100, 200), crop_box)
        tools.assert_equals((100, 100), i.size)
        tools.assert_equals(BLACK, i.getpixel((0, 0)))
예제 #14
0
    def test_flexible_height_doesnt_affect_wider_images(self):
        i = Image.new('RGB', (200, 100), BLACK)
        self.format.flexible_max_height = 200
        self.format.flexible_height = True
        f = Formatter(i, self.format)

        i, crop_box = f.format()
        tools.assert_equals((50, 0, 150, 100), crop_box)
        tools.assert_equals((100, 100), i.size)
예제 #15
0
    def test_important_box_is_used(self):
        i = Image.new('RGB', (200, 100), "red")
        f = Formatter(i, self.format, important_box=(0,0,100,100))
        i.putpixel((99, 99), 0)

        i, crop_box = f.format()
        self.assert_equals((0,0,100,100), crop_box)
        self.assert_equals((100, 100), i.size)
        self.assert_equals((0,0,0), i.getpixel((99,99)))
예제 #16
0
    def test_custom_bg_color_is_used_for_neg_coords(self):
        i = Image.new('RGB', (200, 200), RED)
        f = Formatter(i, self.format, crop_box=(-50, -50, 50, 50))

        i, crop_box = f.format()
        tools.assert_equals((-50, -50, 50, 50), crop_box)
        tools.assert_equals((100, 100), i.size)
        tools.assert_equals(BLUE, i.getpixel((0, 0)))
        tools.assert_equals(RED, i.getpixel((51, 51)))
        tools.assert_equals(RED, i.getpixel((50, 50)))
        tools.assert_equals(RED, i.getpixel((99, 99)))
예제 #17
0
 def get_image_and_formatter(self, name):
     o = Image.open(path.join(self.base, 'data', name))
     f = Formatter(o, self.format)
     return o, f