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.
Share extension gets TWO images from the Photos.app when I select ONE image.
-
My share extension image script works beautifully with selections from the the Files app, but with the Photos app, I have the problem that each image appears TWICE. For the following screenshot I had selected only ONE image, but the script gets TWO (identical) images delivered via
appex.get_images(image_type='ui')
:How can I avoid (or detect) this? I though this might happen because of HDR and normal image, however both images in the list returned from
appex.get_images
are of the same type_ui.Image
. -
@halloleooo do you have the same problem with pil image?
-
@halloleooo As your script process a join of two images, are you 100% sure it is not a bug?
-
@halloleooo this little script prints 1 for an unique photo and 2 if 2 photos shared
import ui import appex class MyView(ui.View): def __init__(self): pass def will_close(self): appex.finish() def main(): v = MyView() v.present() f = appex.get_images(image_type='ui') print(len(f)) if __name__ == '__main__': main()
-
@cvp Well, I copied your code to Pythonista, hooked it up as Share Extension script - and when I run it from the Photos app with ONE image selected it prints 2!
-
@halloleooo HEIC gives 2 photos..., try this with your double photo, the 2nd one is HEIC
Edit : if you want to avoid HEIC photos, go in Settings/Camera/Formats/Most Compatible
import ui import appex class MyView(ui.View): def __init__(self): iv = ui.ImageView(name='iv') iv.frame = self.bounds self.add_subview(iv) def will_close(self): appex.finish() def main(): v = MyView() v.present() f = appex.get_attachments() n = '' for fil in f: i = fil.rfind('/') n += fil[i+1:]+' ' v.name = n v['iv'].image = ui.Image.named(appex.get_attachments()[0]) if __name__ == '__main__': main()
-
@cvp Yep HEIC must be the culprit. So HEIC photos are shared as HEIC and as JPG.
I don’t really understand your code yet, but I will try it. I assume you somehow detect whether the format is HEIC or not...
-
@halloleooo my code allowed to check the file name of your both attachments and thus see one was a jpg and the other an HEIC for the same photo. See the name (title) of the view.
-
@cvp Aha! Yes, of course! I will use this!
Thanks heaps!
-
Just as a final follow-up: Using
appex.get_attachments
andImage.named
works perfectly. Here my workflow:- I get the image file names via
appex.get_attachments
. - I weed out the paths for heic files which have a accompaning other image file.
- Finally I load the remaining images manually via the
Image.named
method.
Thanks for your help, @cvp! :-)
- I get the image file names via