Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
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:
pngdata=ui.Image.from_data(asset.get_image_data().getvalue()).to_png() pil_image=Image.open(io.BytesIO(pngdata))
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.
-
This post is deleted! -
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.
-
@coomlata1 said:
@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.
You can directly convert .heic image to jpg or png using CIContext in Core Image framework since macOS 10.13