Ejemplo n.º 1
0
    def assert_resize_image(self,
                            filename,
                            width,
                            height,
                            mode,
                            expected_width=None,
                            expected_height=None):
        if expected_width == None: expected_width = width
        if expected_height == None: expected_height = height

        filename = self.get_test_image_path(filename)
        ext = get_ext(filename)
        dst_filename = os.path.join(tempfile.gettempdir(),
                                    'resized_image.%s' % ext)

        resize_image(filename, dst_filename, width, height, mode)

        self.assertTrue(os.path.isfile(dst_filename), 'file exists')
        self.assertTrue(is_image(dst_filename), 'is image file')

        # check image size
        size = get_image_size(dst_filename)
        self.assertEqual(
            size[0], expected_width,
            'expected image width of %d, but was %d.' %
            (expected_width, size[0]))
        self.assertEqual(
            size[1], expected_height,
            'expected image height of %d, but was %d.' %
            (expected_height, size[1]))
Ejemplo n.º 2
0
 def test_should_return_image_size_in_pixels(self):
     for image in TEST_IMAGES:
         filename = self.get_test_image_path(image.filename)
         if get_ext(filename) != 'svg':
             image_size = get_image_size(filename)
             self.assertEqual(image_size[0], image.width, '%s: width should be %d but was %d' % (image.filename, image.width, image_size[0]))
             self.assertEqual(image_size[1], image.height, '%s: height should be %d but was %d' % (image.filename, image.height, image_size[1]))
Ejemplo n.º 3
0
    def resize_image_copy_if_too_wide(self, filename):
        filename = self.get_test_image_path(filename)
        ext = get_ext(filename)
        dst_filename = os.path.join(tempfile.gettempdir(), 'resized_image_copy.%s' % ext)
        shutil.copyfile(filename, dst_filename)

        resized = resize_image_if_too_wide(dst_filename)

        width, height = get_image_size(dst_filename)
        os.remove(dst_filename)
        return (resized, width, height)
Ejemplo n.º 4
0
 def test_should_raise_ioerror_if_not_an_image(self):
     with self.assertRaises(IOError):
         get_image_size(self.get_test_image_path('test.txt'))
Ejemplo n.º 5
0
 def test_should_return_image_size_in_pixels_for_svg_image(self):
     image_size = get_image_size(self.get_test_image_path('test.svg'))
     self.assertEqual(164, image_size[0])
     self.assertEqual(84, image_size[1])