How to get the underlying file name when using get_images() and not get_attachments()?
A new chapter with my Image Share Extension:
I started using
appex.get_images, because with
get attachmentsI get the path name and thus can check for HEIC images with the same name as JPGs. This is great for the Photos app.
However in the Files app I get via
get_attachmentsduplicates for the same file path!
get_images(image_tyepe='ui')still gives me only single files.
Here some debug output with two files selected in the Files app when calling the Share Extension.
get_attachments list: /private/var/mobile/Library/Mobile Documents/com~apple~CloudDocs/Journals/Diary/_assets/Aubergine-menu_MAR2021_Julia.jpg /private/var/mobile/Library/Mobile Documents/com~apple~CloudDocs/Journals/Diary/_assets/Aubergine-menu_MAR2021_Julia.jpg /private/var/mobile/Library/Mobile Documents/com~apple~CloudDocs/Journals/Diary/_assets/Aubergine-menu_MAR2021_Leo.jpg /private/var/mobile/Library/Mobile Documents/com~apple~CloudDocs/Journals/Diary/_assets/Aubergine-menu_MAR2021_Leo.jpg get_images list <_ui.Image object at 0x1162F7240> <_ui.Image object at 0x1162F7550>
So I clearly prefer using
get_images! But then I do not know the name and extension of the underlying file (for the HEIC deduping). - Any way to get this?
Many thanks for pointers in advance!
Running an attachment through the console, you can take it step by step, so based on your argument for get_images(), run through each item via for loop, and access the .name property. Without your argument it would return a PIL object, and you can access it via .filename or .fp.name
@ts he does not want a pil but an ui.image, for memory problem reasons in appex mode
Got it (finally, same as @ts first post)
import appex imgs = appex.get_images(image_type='ui') print(len(imgs)) print(dir(imgs)) for img in imgs: print(img.name)
@cvp Yes, I noticed , because I got “AttributeError: '_ui.Image' object has no attribute 'format'”.
I’ll try your new suggestion. Thanks!
@halloleooo yes, sorry, my first (deleted and purged) answer was using format but only valid with pil