forked from pyodide/pyodide
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
9907f1c
commit 61b6411
Showing
3 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |