initial attempt at plugin

This commit is contained in:
David Poirier 2020-07-11 18:04:35 +10:00
parent f760e1fd5a
commit cbc9318924
6 changed files with 42 additions and 0 deletions

BIN
IMG_3616.HEIC Normal file

Binary file not shown.

View 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")

View File

@ -98,6 +98,7 @@ _plugins = [
"GifImagePlugin", "GifImagePlugin",
"GribStubImagePlugin", "GribStubImagePlugin",
"Hdf5StubImagePlugin", "Hdf5StubImagePlugin",
"HeifImagePlugin",
"IcnsImagePlugin", "IcnsImagePlugin",
"IcoImagePlugin", "IcoImagePlugin",
"ImImagePlugin", "ImImagePlugin",

BIN
tree-with-transparency.heic Normal file

Binary file not shown.

3
venv/pyvenv.cfg Normal file
View 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

BIN
x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 MiB