コード例 #1
0
    def test_add_border__pixels_over_ratio_are_cropped(self):
        ratio = (2, 3)
        (img_w_mm, img_h_mm) = (100, 150)
        border_mm = 0  # No border needed in this test

        (img_w_px, img_h_px) = (100 + 1, 150 + 2)
        self.fake_image_size((img_w_px, img_h_px))

        commands = img_add_border.add_border('in.jpg', ratio,
                                             (img_w_mm, img_h_mm), border_mm,
                                             WHITE)

        self.assert_command(commands, 'convert', [['-extent', '100x150']])
コード例 #2
0
    def test_add_border__10x15cm_portrait__crop_height(self):
        ratio = (2, 3)
        (img_w_mm, img_h_mm) = (100, 150)
        border_mm = 10

        (img_w_px, img_h_px) = (960, 1560 + 100)
        self.fake_image_size((img_w_px, img_h_px))

        commands = img_add_border.add_border('in.jpg', ratio,
                                             (img_w_mm, img_h_mm), border_mm,
                                             WHITE)

        self.assert_command(commands, 'convert', [['-extent', '960x1560']])
        self.assert_command(commands, 'convert', [['-border', '120x120']])
コード例 #3
0
    def test_add_border__10x15cm_landscape__crop_width(self):
        ratio = (3, 2)
        (img_w_mm, img_h_mm) = (150, 100)
        border_mm = 10

        (img_w_px, img_h_px) = (1560 + 100, 960)
        self.fake_image_size((img_w_px, img_h_px))

        commands = img_add_border.add_border('in.jpg', ratio,
                                             (img_w_mm, img_h_mm), border_mm,
                                             WHITE)

        self.assert_command(commands, 'convert', [['-extent', '1560x960']])
        self.assert_command(commands, 'convert', [['-border', '120x120']])
コード例 #4
0
    def test_add_border__10x15cm_landscape__no_crop(self):
        ratio = (3, 2)
        (img_w_mm, img_h_mm) = (150, 100)
        border_mm = 10

        (img_w_px, img_h_px) = (1560, 960)
        self.fake_image_size((img_w_px, img_h_px))

        commands = img_add_border.add_border('in.jpg', ratio,
                                             (img_w_mm, img_h_mm), border_mm,
                                             WHITE)

        # Cropping is not needed.
        self.assert_no_such_command(commands, 'convert', [['-extent']])
        # Added border 5 px on all sides.
        self.assert_command(commands, 'convert', [['-border', '120x120']])
コード例 #5
0
    def test_add_border__artificial_square(self):
        ratio = (1, 1)
        (img_w_mm, img_h_mm) = (4, 4)
        border_mm = 1

        (img_w_px, img_h_px) = (10, 10)
        self.fake_image_size((img_w_px, img_h_px))

        commands = img_add_border.add_border('in.jpg', ratio,
                                             (img_w_mm, img_h_mm), border_mm,
                                             WHITE)

        # Cropping is not needed.
        self.assert_no_such_command(commands, 'convert', [['-extent']])
        # Added border 5 px on all sides.
        self.assert_command(commands, 'convert', [['-border', '5x5']])
コード例 #6
0
    def test_add_border__convert_dpi(self):
        ratio = (2, 3)
        img_w_mm = img_add_border.convert_to_mm(4, 'inch')
        img_h_mm = img_add_border.convert_to_mm(6, 'inch')
        border_mm = 0  # No border needed in this test

        (img_w_px, img_h_px) = (5000, 5000)
        self.fake_image_size((img_w_px, img_h_px))

        commands = img_add_border.add_border('in.jpg',
                                             ratio, (img_w_mm, img_h_mm),
                                             border_mm,
                                             WHITE,
                                             dpi=300)

        self.assert_command(commands, 'convert',
                            [['-density', '300'], ['-resize', '1200x1800']])