def test_exif_rotation(): print("Test rotation of image") bytes = base64_to_bytes(sample_base64_rotated) img = Image.open(bytes) img2Bytes = rotate_image_by_exif(bytes, 270, ImageType.JPEG) img2 = Image.open(img2Bytes) assert img.width == img2.height
def test_convert_image_to_bytes(): print("Converting test base64 string to bytes - image - bytes - image") bytes = base64_to_bytes(sample_base64) img = Image.open(bytes) bytes2 = image_to_bytes(img, ImageType.JPEG) img2 = Image.open(bytes2) assert img2.width == img.width
def test_image_crop(): print("Test image crop reduce by 10%") bytes = base64_to_bytes(sample_base64) img2bytes = crop_image(bytes, 0.1, ImageType.JPEG) img2 = Image.open(img2bytes) new_width = img2.width new_height = img2.height assert new_width == 51 assert new_height == 44
def test_image_resize_landscape(): print("Test image resize max size 50 landscape") bytes = base64_to_bytes(sample_base64) img2bytes = resize_image(bytes, 50, ImageType.JPEG) img2 = Image.open(img2bytes) new_width = img2.width new_height = img2.height assert new_width == 50 assert new_height == 42
def test_image_resize_portrait(): print("Test image resize max size 50 portrait") bytes = base64_to_bytes(sample_base64_rotated) bytes2 = rotate_image_by_exif(bytes, 270, ImageType.JPEG) img2bytes = resize_image(bytes2, 50, ImageType.JPEG) img2 = Image.open(img2bytes) new_width = img2.width new_height = img2.height assert new_width == 43 assert new_height == 50
def do_inference_from_base_64(learn, image_base64, image_format): bytes = base64_to_bytes(image_base64) return do_inference(learn, bytes, image_format)
def test_exif_with_rotation(): print("Sample image with rotation") bytes = base64_to_bytes(sample_base64_rotated) result = get_exif_rotation(bytes) assert result == 270
def test_exif_no_rotation(): print("Sample image with no rotation") bytes = base64_to_bytes(sample_base64) result = get_exif_rotation(bytes) assert result == 0
def test_convert_to_bytes(): print("Converting test base64 string to bytes") bytes = base64_to_bytes(sample_base64) img = Image.open(bytes) assert img.width == 63