Ejemplo n.º 1
0
 def test_full_flip_3(self, resources):
     expected_result = resources / "imforge" / "crop" / "expected" / "pil" / "full_flip_3.png"
     crop_box = [(389, 177), (389, 0), (0, 0), (0, 177)]
     with Image.open(resources / "some_text.jpg") as image:
         cropped_image = crop_pil(image, crop_box)
         if self.DEBUG:
             cropped_image.show()
             if not expected_result.exists():
                 cropped_image.save(expected_result, optimize=True)
         image_bytes = BytesIO()
         cropped_image.save(image_bytes, format="png", optimize=True)
     image_bytes.seek(0)
     assert image_bytes.read() == expected_result.read_bytes()
Ejemplo n.º 2
0
 def test_crop_near_edge(self, resources):
     expected_result = resources / "imforge" / "crop" / "expected" / "pil" / "crop_near_edge.png"
     crop_box = [(102, 750), (101, 529), (324, 528), (322, 750)]
     with Image.open(resources / "qrcode_multi.png") as image:
         cropped_image = crop_pil(image, crop_box, fillcolor=(255, 0, 0))
         if self.DEBUG:
             cropped_image.show()
             if not expected_result.exists():
                 cropped_image.save(expected_result, optimize=True)
         image_bytes = BytesIO()
         cropped_image.save(image_bytes, format="png", optimize=True)
     image_bytes.seek(0)
     assert image_bytes.read() == expected_result.read_bytes()
Ejemplo n.º 3
0
 def test_crop_flip_out_of_image_clip(self, resources):
     expected_result = resources / "imforge" / "crop" / "expected" / "pil" / "crop_flip_out_of_image_clip.png"
     crop_box = [(-15, 0), (325, 161), (14, 71), (368, 78)]
     with Image.open(resources / "some_text.jpg") as image:
         cropped_image = crop_pil(image, crop_box, clip=True)
         if self.DEBUG:
             cropped_image.show()
             if not expected_result.exists():
                 cropped_image.save(expected_result, optimize=True)
         image_bytes = BytesIO()
         cropped_image.save(image_bytes, format="png", optimize=True)
     image_bytes.seek(0)
     assert image_bytes.read() == expected_result.read_bytes()
Ejemplo n.º 4
0
 def test_crop_flip_complex(self, resources):
     expected_result = resources / "imforge" / "crop" / "expected" / "pil" / "crop_flip_complex.png"
     crop_box = [(15, 8), (-15, 50), (200, 200), (450, 161), (368, 78)]
     with Image.open(resources / "some_text.jpg") as image:
         ImageDraw.ImageDraw(image).polygon(crop_box, outline=(0, 0, 255))
         cropped_image = crop_pil(image, crop_box, fillcolor=(255, 0, 255), cut_out=True, clip=True)
         if self.DEBUG:
             cropped_image.show()
             if not expected_result.exists():
                 cropped_image.save(expected_result, optimize=True)
         image_bytes = BytesIO()
         cropped_image.save(image_bytes, format="png", optimize=True)
     image_bytes.seek(0)
     assert image_bytes.read() == expected_result.read_bytes()