Pythonista-Issues
Pythonista-Issues copied to clipboard
Cannot import images taken with the Camera app via Photos library
I find that when trying to import some images from the photo library, a NoneType error occurs. This happens with the most basic using of the Pythonista photos library, such the first example script in the documentation:
# Get the last photo, and show it in the console
import photos
all_assets = photos.get_assets()
last_asset = all_assets[-1]
img = last_asset.get_image()
img.show()
If that last image is an unedited photo take with the Camera app, the script fails with the following traceback:
File "/private/var/mobile/Containers/Shared/AppGroup/8B27B52F-60FF-49C5-B4BF-1F7F23455B25/Pythonista3/Documents/Example.py", line 6, in <module>
img = last_asset.get_image()
File "/var/containers/Bundle/Application/75EA0E35-43A6-4AD3-8071-B03172805713/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/PIL/Image.py", line 2328, in open
if not accept or accept(prefix):
File "/var/containers/Bundle/Application/75EA0E35-43A6-4AD3-8071-B03172805713/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/PIL/HeicImagePlugin.py", line 33, in _accept
uti = str(ObjCInstance(c.CGImageSourceGetType(src)))
File "/var/containers/Bundle/Application/75EA0E35-43A6-4AD3-8071-B03172805713/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/objc_util.py", line 547, in __str__
return desc_str.decode('utf-8')
AttributeError: 'NoneType' object has no attribute 'decode'
I believe this issue was first noted in #574. However, it really isn’t about live images; editing one (for example, applying “magic wand” auto) allows the image to be imported with .get_image
. Images in the photo library created by methods (such as taking a screenshot on device, or images saved from other apps or web downloads) also seem to work fine. Switching to .get_ui_image()
also seems to work, so it’s just trying to use the customized PIL where the issue happens.
I’ve tried this on iOS 13.3, with images that go back quite a while.