def test_doesnt_get_smaller_than_focal_point(self): "Test that the cropbox doesn't get any smaller than the focal point" self.assertEqual( crop_to_point((640, 480), (10, 10), FocalPoint(x=320, y=240, width=100, height=100)), CropBox(270, 190, 370, 290), )
def test_keeps_composition(self): "Test that the cropbox tries to keep the composition of the original image as much as it can" self.assertEqual( crop_to_point((300, 300), (150, 150), FocalPoint(x=100, y=200)), CropBox( 50, 100, 200, 250), # Focal point is 1/3 across and 2/3 down in the crop box )
def test_keeps_focal_point_in_view_bottom_left(self): """ Even though it tries to keep the composition of the image, it shouldn't let that get in the way of keeping the entire subject in view """ self.assertEqual( crop_to_point((300, 300), (150, 150), FocalPoint(x=100, y=200, width=150, height=150)), CropBox(25, 125, 175, 275), )
def crop_to_point(self, image, size, focal_point): crop_box = crop.crop_to_point(image.size, size, focal_point) # Don't crop if we don't need to if crop_box.size != image.size: image = self.crop(image, crop_box) # If the focal points are too large, the cropping system may not # crop it fully, resize the image if this has happened: if crop_box.size != size: image = self.resize_to_fill(image, size) return image
def test_keeps_composition(self): "Test that the cropbox tries to keep the composition of the original image as much as it can" self.assertEqual( crop_to_point((300, 300), (150, 150), FocalPoint(x=100, y=200)), CropBox(50, 100, 200, 250), # Focal point is 1/3 across and 2/3 down in the crop box )
def test_doesnt_exit_bottom_right(self): "Test that the cropbox doesn't exit the image at the bottom right" self.assertEqual( crop_to_point((640, 480), (100, 100), FocalPoint(x=640, y=480)), CropBox(540, 380, 640, 480), )
def test_doesnt_exit_top_left(self): "Test that the cropbox doesn't exit the image at the top left" self.assertEqual( crop_to_point((640, 480), (100, 100), FocalPoint(x=0, y=0)), CropBox(0, 0, 100, 100), )
def test_basic_no_focal_point(self): "If focal point is None, it should make one in the centre of the image" self.assertEqual( crop_to_point((640, 480), (100, 100), None), CropBox(270, 190, 370, 290), )
def test_basic(self): "Test basic cropping in the centre of the image" self.assertEqual( crop_to_point((640, 480), (100, 100), FocalPoint(x=320, y=240)), CropBox(270, 190, 370, 290), )