diff --git a/packages/pi-heif/meta.yaml b/packages/pi-heif/meta.yaml new file mode 100644 index 00000000000..0c20fd5a273 --- /dev/null +++ b/packages/pi-heif/meta.yaml @@ -0,0 +1,30 @@ +package: + name: pi-heif + version: 0.21.0 + top-level: + - pi_heif +source: + url: https://files.pythonhosted.org/packages/f5/12/e87b1a7e5b353f885b646ee9c966be74b7db0ae9d68abc712411487353d7/pi_heif-0.21.0.tar.gz + sha256: 4902cdb84e75505e1d9abdd5aff1e6dcfebe569ec825162d68a4a399a43689a4 +requirements: + run: + - cffi + - Pillow + - libheif + host: + - cffi + - libheif +build: + script: | + export LIBHEIF_ROOT=${WASM_LIBRARY_DIR} +test: + imports: + - pi_heif +about: + home: https://github.com/bigcat88/pillow_heif + PyPI: https://pypi.org/project/pi_heif + summary: Python 3.6+ interface to libheif library + license: LGPL-2.1 +extra: + recipe-maintainers: + - airen1986 diff --git a/packages/pi-heif/test_data/tree-with-transparency.heic b/packages/pi-heif/test_data/tree-with-transparency.heic new file mode 100644 index 00000000000..346ae48c633 Binary files /dev/null and b/packages/pi-heif/test_data/tree-with-transparency.heic differ diff --git a/packages/pi-heif/test_pi_heif.py b/packages/pi-heif/test_pi_heif.py new file mode 100644 index 00000000000..70d7549c0d8 --- /dev/null +++ b/packages/pi-heif/test_pi_heif.py @@ -0,0 +1,48 @@ +import base64 +import pathlib + +from pytest_pyodide import run_in_pyodide + +DEMO_PATH = pathlib.Path(__file__).parent / "test_data" +SAMPLE_IMAGE = base64.b64encode( + (DEMO_PATH / "tree-with-transparency.heic").read_bytes() +) + + +def test_heif(selenium): + @run_in_pyodide(packages=["Pillow", "pi-heif"]) + def _test_heif_inner(selenium, image_base64): + import base64 + + with open("tree-with-transparency.heic", "wb") as f: + f.write(base64.b64decode(image_base64)) + + import pi_heif + + if pi_heif.is_supported("tree-with-transparency.heic"): + heif_file = pi_heif.open_heif( + "tree-with-transparency.heic", convert_hdr_to_8bit=False + ) + assert heif_file.mode == "RGBA" + + _test_heif_inner(selenium, SAMPLE_IMAGE) + + +def test_pillow(selenium): + @run_in_pyodide(packages=["Pillow", "pillow-heif"]) + def _test_pillow_inner(selenium, image_base64): + import base64 + + with open("tree-with-transparency.heic", "wb") as f: + f.write(base64.b64decode(image_base64)) + + from pi_heif import register_heif_opener + from PIL import Image + + register_heif_opener() + + im = Image.open("tree-with-transparency.heic") + assert im.size == (262, 264) + assert im.mode == "RGBA" + + _test_pillow_inner(selenium, SAMPLE_IMAGE)