Forum Archive

Share extension gets TWO images from the Photos.app when I select ONE image.

halloleooo

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 viaappex.get_images(image_type='ui'):

Share extension with ONE image selected

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.

cvp

@halloleooo do you have the same problem with pil image?

cvp

@halloleooo As your script process a join of two images, are you 100% sure it is not a bug?

cvp

@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()
halloleooo

@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!

cvp

@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()
halloleooo

@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...

cvp

@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.

halloleooo

@cvp Aha! Yes, of course! I will use this!

Thanks heaps!

halloleooo

Just as a final follow-up: Using appex.get_attachments and Image.named works perfectly. Here my workflow:

  1. I get the image file names via appex.get_attachments.
  2. I weed out the paths for heic files which have a accompaning other image file.
  3. Finally I load the remaining images manually via the Image.named method.

Thanks for your help, @cvp! :-)