Skip to content

Commit

Permalink
add package pi-heif (pyodide#5243)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
airen1986 and pre-commit-ci[bot] authored Dec 7, 2024
1 parent 9907f1c commit 61b6411
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
30 changes: 30 additions & 0 deletions packages/pi-heif/meta.yaml
Original file line number Diff line number Diff line change
@@ -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
Binary file not shown.
48 changes: 48 additions & 0 deletions packages/pi-heif/test_pi_heif.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 61b6411

Please sign in to comment.