-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for HEIC/HEIF files #436
Comments
I have been playing around with this a bit. The first immediate plate the user experiences an error is the following: First, lots of these error during the "Collecting albums" step:
Then:
If sigal build is run with --debug, then it stops earlier producing this error:
Inside PIL: ./venv/lib/python3.7/site-packages/PIL/Image.py line 3023:
It appears that it fails due to a problem in PIL.Image. According to this stackoverflow post, it is possible to use pyheif to load HEIF/HEIC images with PIL.Image: The example looks like this:
Would it make sense to use the same method to have sigal support HEIF images? There are other methods proposed in the SO post that might be relevant. |
I think I almost fixed this using pyheif. This is the code change I made to image.py:
It now kinda works in that it actually reads the .heic images. However, when generating the thumbnails it fails because the thumbnails are now generated as jpeg format (which is correct) but the filename generated is still .heic (which is now incorrect as the file is no longer a heic file but a jpeg file). I have inserted a hack with the try/except where I catch the ValueError. This ValueError is raised when sigal tries to generate thumbnails and opens a .heic file and then my conditional that checks if extension is ".heic" evaluates to True. However, the file is not a heif image. So pyheif fails causing the ValueError. My hack is then to just read the file normally using PILImage.open(). But, alas, this does not solve the file naming errors. I think the file naming issues should be solvable in that they are very similar to how png files are handled. Here we also have different extensions and format. The difference is that a source PNG image will always be a PNG image. Even in the thumbnails. I really hope that someone more experienced with this codebase will help implement this. |
https://pypi.org/project/pyheif-pillow-opener/ is mentioned in the Pillow issue, seems a nice and easy way. |
That does seem like an easy way to Just Fix it. Hopefully that'll work. |
Hmm, for thumbnail extensions I don't remember exactly the status, |
Is this something you need help fixing? I am not a strong front-end dev, so not sure if I am the right person to take this on. |
I have tried replacing:
With:
In image.py and gallery.py. The hope what that it would mostly work transparently. However, I get this exception:
No sure how to proceed. Full debug output is available here: |
Interesting, we cannot use this format for resized images and thumbnails, so saving should be forced to jpeg. But currently there is no real logic in the code to tell with output format is valid or not, and which formats should be converted. Fixing that is probably not that simple. |
Hi, Could this be solved by having a Format class that describes an image format. Each format has a name, e.g. JPEG, PNG, etc. and a list of extensions which will match this format. Ie. if sigal encounters a file that matches a format's extension, then sigal will assume the file is in that format. Please see the code sample below to illustrate what I mean.
|
I think we can have something simpler, and I don't want to maintain a list of which formats are supported by pillow. All we need is to define the formats that can be used for resized images and thumbnails, all the other would need to be converted. There is already a setting to force output images to a specific format, we probably need another one for the format to which images would be converted if there are not a valid output format.
|
Is this enough, to support HEIF for Sigal?
|
@bigcat88 - |
@saimn yes, it is one of two ways to register it as a plugin. |
@bigcat88 - so I guess you would need to make a plugin for sigal to register the Pillow plugin ? |
@saimn no, i not need to, thanks. Do not want to add for plugin in settings['plugins']:
try:
if isinstance(plugin, str):
mod = importlib.import_module(plugin)
mod.register(settings) # Add here a check to not call `regsiter` when it is not present.
else:
plugin.register(settings)
logger.debug('Registered plugin %s', plugin)
except Exception as e:
logger.error('Failed to load plugin %s: %r', plugin, e) currently it works, just logs an error during register... |
Hmm ok but you're using sigal's plugin registration to register a Pillow plugin, relying on the fact that sigal is importing the plugin... |
So I tried extracting enough information from this to make a HEIF gallery, but I didn't get it to work.
I had a very weird error where
Definitely not the right solution, I know, but after that,
for which I don't even have a clue where to start fixing this. Help very welcome. |
@0-wiz-0 can you test with |
@bigcat88 : Fails the same way with version 0.9.3 of pillow_heif. |
Just adding to config Simple solution to move import to # Force loading of truncated files
ImageFile.LOAD_TRUNCATED_IMAGES = True
from pillow_heif import HeifImagePlugin # <---- add this line without comment ofc
def _has_exif_tags(img):
return hasattr(img, "info") and "exif" in img.info |
I'll try that, thanks. try:
# Pillow 7.2+
from PIL.TiffImagePlugin import IFDRational
except ImportError:
IFDRational = None I think it'd be good to do it the same way for heif support - try an import and if it fails, handle that (in the places that need it, if any). |
Ok, so with:
and
in the config file, I get a gallery for HEIC images - yay! |
Does this mean that your version is working with HEIC images in the source images and then having those presented in the gallery as jpeg? If this works, will this be included in the next release of Sigal? |
Apple now uses HEIF by default - be nice to have it working one way or another. thanks!! |
I agree that HEIF/HEIC should be supported. It is unclear to me whether it actually is supported or not. The message above from @0-wiz-0 seems to indicate that it is supported? |
@thomasdn No, I think it still needs to be patched with the changes from #436 (comment) to support HEIF. |
I see. @saimn would you be merging this patch? |
There is a PR (#519) but it needs a rebase and it would be great to have a test image to make sure it works. If someone wants to help finalizing it... |
Newer Apple devices such as iPhone or iPads take photos in the HEIF format1. These photos are using the .heic extension.
Sigal does not seem to include the .heic files in the generated gallery.
Sigal seems to use the Pillow module for image manipulation. Pillow seems to support the HEIF format2, so I see no reason that sigal shouldn't automatically include .heic images present in the source folder.
The text was updated successfully, but these errors were encountered: