2023-02-06 15:00:47 +01:00
|
|
|
import io
|
2023-02-07 14:00:19 +01:00
|
|
|
from pathlib import Path
|
2023-02-06 15:00:47 +01:00
|
|
|
|
|
|
|
from PIL import Image
|
|
|
|
|
|
|
|
from lama_cleaner.helper import pil_to_bytes
|
|
|
|
|
|
|
|
|
2023-02-07 14:00:19 +01:00
|
|
|
current_dir = Path(__file__).parent.absolute().resolve()
|
|
|
|
png_img_p = current_dir / "image.png"
|
|
|
|
jpg_img_p = current_dir / "bunny.jpeg"
|
|
|
|
|
|
|
|
|
2023-02-06 15:00:47 +01:00
|
|
|
def print_exif(exif):
|
|
|
|
for k, v in exif.items():
|
|
|
|
print(f"{k}: {v}")
|
|
|
|
|
|
|
|
|
|
|
|
def test_png():
|
2023-02-07 14:00:19 +01:00
|
|
|
img = Image.open(png_img_p)
|
2023-02-06 15:00:47 +01:00
|
|
|
exif = img.getexif()
|
|
|
|
print_exif(exif)
|
|
|
|
|
|
|
|
pil_bytes = pil_to_bytes(img, ext="png", exif=exif)
|
|
|
|
|
|
|
|
res_img = Image.open(io.BytesIO(pil_bytes))
|
|
|
|
res_exif = res_img.getexif()
|
|
|
|
|
|
|
|
assert dict(exif) == dict(res_exif)
|
|
|
|
|
|
|
|
|
|
|
|
def test_jpeg():
|
2023-02-07 14:00:19 +01:00
|
|
|
img = Image.open(jpg_img_p)
|
2023-02-06 15:00:47 +01:00
|
|
|
exif = img.getexif()
|
|
|
|
print_exif(exif)
|
|
|
|
|
|
|
|
pil_bytes = pil_to_bytes(img, ext="jpeg", exif=exif)
|
|
|
|
|
|
|
|
res_img = Image.open(io.BytesIO(pil_bytes))
|
|
|
|
res_exif = res_img.getexif()
|
|
|
|
|
|
|
|
assert dict(exif) == dict(res_exif)
|