Heic photo file issues in iOS11
With the introduction of iOS11, photos on the iPhone camera roll are stored in .heic format rather than jpg. Anyone have any thoughts on:
- How to retrieve metadata from the .heic photo files using pythonista
- How to convert said files from .heic to jpg format using pythonista
You can set the iPhone camera to store pics in jpeg format in iOS11 by selecting 'Camera' in settings, selecting 'Format', and changing the setting from 'High Efficiency' to 'Most Compatible'. Downside to this is the larger storage size using jpeg and video quality will suffer.
I would prefer to use the heic format, but most third party modules that work with images don't yet support heic.
Have you tried the photos module yet? From what i gather, meta data would work the same as it does now (need to get the avasset, etc). Also, I gather that incompatible apps would get the jpeg representation automatically -- if not, there is an ObjC method to get one.
@ JonB...Thanks for the response. I'm importing image, imagefont, and imagedraw from PIL and using them to open, resize, reorient if necessary, and then stamp GPS data to bottom of photo before copying it to a folder in dropbox. User has the option to retain the metadata in the Dropbox copy. Full code is here.
I can get the metadata from the heic photo without problems, but PIL chokes on the photo during the opening and resizing, so I'm bypassing any that exist in the camera roll when I run the script.
As I have thought about this more, I would prefer to keep the camera roll photos in heic format, rather than converting to jpeg, due to the more efficient storage capabilities. I imagine that PIL or Pillow will be updated to accommodate heic at some point in the future.
you might try converting first to a ui.Image, then to png, which should be readable by pil:
The UIImage underlying methods should (I think) handle heic, and you only lose quality once (when you finally write to jpg), though the png may be pretty large. I haven't tried this since i dont have ios11.
Another option may be to use c.UIImageJPEGRepresentation to convert the Objcinstance of the ui.Image to jpeg to go into pil.
Finally, you might get faster results by by using PHImageManager, since you can request a specific size, and thus maybe skip the pil resize step. That requires some objc_util use, and a ObjCBlock, which might be tricky.
@JonB...Thanks much for the useful information. I’ll follow up on your suggestions and see where Objective C and PHImageManager leads me. Hopefully I will have some useful code to present in the near future.
Hi, I totally agree with what u said. JPG takes up larger storage space compared with HEIC. However, some third party modules that work with images have not been developed yet. There is a long way to go to solve this problem from technical level. What I can provide to u is my experience of converting HEIC images. I knew a heic converter portable tool. It can convert HEIC images with perfect performance and without scarifying original quality. What's more, it is supportable to keep all EXIF metadata so that u don't have to worry about any image information loss. Hope it is useful!
There are a lot of related software, you can read the best heic converter reviews to choose the best one after a comprehensive comparison of them.