mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-22 21:24:46 +03:00
initial attempt at plugin
This commit is contained in:
parent
f760e1fd5a
commit
cbc9318924
BIN
IMG_3616.HEIC
Normal file
BIN
IMG_3616.HEIC
Normal file
Binary file not shown.
38
src/PIL/HeifImagePlugin.py
Normal file
38
src/PIL/HeifImagePlugin.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
import io
|
||||
|
||||
from . import Image, ImageFile
|
||||
|
||||
try:
|
||||
import pyheif
|
||||
print("!")
|
||||
except ImportError:
|
||||
pyheif = None
|
||||
|
||||
def _accept(prefix):
|
||||
check = pyheif.check(prefix)
|
||||
return check != pyheif.heif_filetype_no
|
||||
|
||||
|
||||
class HeifImageFile(ImageFile.ImageFile):
|
||||
format = "HEIF"
|
||||
format_description = "HEIF Image File Format"
|
||||
|
||||
def _open(self):
|
||||
b = self.fp.read()
|
||||
if not _accept(b):
|
||||
raise ValueError("Not a HEIF image file")
|
||||
|
||||
heif_file = pyheif.read(b)
|
||||
self._size = heif_file.size
|
||||
self.mode = heif_file.mode
|
||||
self.fp = io.BytesIO(heif_file.data)
|
||||
self.tile = [("raw", (0, 0) + heif_file.size, 0, (heif_file.mode, heif_file.stride))]
|
||||
|
||||
|
||||
if pyheif:
|
||||
print("!!")
|
||||
Image.register_open(HeifImageFile.format, HeifImageFile, _accept)
|
||||
Image.register_extensions(HeifImageFile.format, [".heif", ".heic", ".hif"])
|
||||
Image.register_mime(HeifImageFile.format, "image/heif")
|
||||
Image.register_mime(HeifImageFile.format, "image/heic")
|
||||
|
|
@ -98,6 +98,7 @@ _plugins = [
|
|||
"GifImagePlugin",
|
||||
"GribStubImagePlugin",
|
||||
"Hdf5StubImagePlugin",
|
||||
"HeifImagePlugin",
|
||||
"IcnsImagePlugin",
|
||||
"IcoImagePlugin",
|
||||
"ImImagePlugin",
|
||||
|
|
BIN
tree-with-transparency.heic
Normal file
BIN
tree-with-transparency.heic
Normal file
Binary file not shown.
3
venv/pyvenv.cfg
Normal file
3
venv/pyvenv.cfg
Normal file
|
@ -0,0 +1,3 @@
|
|||
home = /usr/local/Cellar/python@3.8/3.8.3_2/bin
|
||||
include-system-site-packages = false
|
||||
version = 3.8.3
|
Loading…
Reference in New Issue
Block a user