def test_resize(self): name, width, height = resize(self.img_location, 'images/test_image_small.jpg', 400) self.assertEqual(name, 'images/test_image_small.jpg') self.assertEqual(width, 400) self.assertEqual(height, 300) # preserves aspect ratio and creates new files as needed, returning correct name name, width, height = resize(self.img_location, 'images/test_image_small.jpg', 200, 200) self.assertEqual(name, 'images/test_image_small_1.jpg') self.assertEqual(width, 200) self.assertEqual(height, 150) # just double check to be sure it got saved here self.assertTrue('images/test_image_small_1.jpg' in self.storage._files) img_buf = StringIO(self.storage._files['images/test_image_small_1.jpg']) img = Image.open(img_buf) self.assertEqual((200, 150), img.size)
def test_resize_to_same(self): # a special case that ensures resizing an image to the same destination # does not result in multiple files being created name, width, height = resize(self.img_location, self.img_location, 400) # check that it was resized and saved here img_buf = StringIO(self.storage._files[self.img_location]) img = Image.open(img_buf) self.assertEqual((400, 300), img.size)
def delayed_resize(source, dest, width, height=None): resize(source, dest, width, height)