omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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.


    Copy photo from album to album

    Pythonista
    3
    6
    3380
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • jm2466
      jm2466 last edited by

      I tried searching but it was not clear from what I found. I want to copy a photo from one album to another without creating a physical copy. In some of the examples it appears the image is opened, some reference a temp jpg on the file system or something. Anyhow I thought I could just get a reference/pointer to the photo from one album then add that reference to the other album. Anyone do this in straight python or does it require objc calls?

      Thanks

      1 Reply Last reply Reply Quote 0
      • JonB
        JonB last edited by

        Assets in the photos module are essentially thin objects that point to actual image data. so, the images assets that you get from photos.get_assets, or from an album's assets can be added to other albumns without creating copies.

        #copy all albumns from first to second album
        src=photos.get_albumns()[0]
        dest=photos.get_albumns()[1]
        if dest.can_add_assets:
            dest.add_asset(src.assets)
        else:
           print('could not add')
        # add a single asset, must still be list
        dest.add_assets([photos.get_assets()[0] ])
        

        obviously, you would usually check the name of the albumn, etc. not all albumns can add assets, such as autogenerated albumns.

        1 Reply Last reply Reply Quote 0
        • jm2466
          jm2466 last edited by

          Thanks! That worked. Now just having a bit of an issue decoding the exif.

          Here is what I am trying to do. I have 2 albums from a recent vacation with a lot of photos in each. One is from my phone (all live photos) and the other is from my dslr. They are each in date/time order and I want to merge both into one album sorted by date/time (I want to do this on the phone as to not lose the live photos). This logic is fairly easy as long as I can get photos from the two albums (which I can now - thanks!) and get the exif info from each to compare (the dates outside the exif may not reflect the actual time the picture was taken). The Image.info appears to have the exif data but looks to be Unicode or something. Have not had a chance to look into it further yet so if you have a quick solution to this that would be great.

          Thanks again

          1 Reply Last reply Reply Quote 0
          • JonB
            JonB last edited by

            See https://forum.omz-software.com/topic/1178/reading-exif-data-from-photo

            photos.get_metadata might work for pictures taken by the phone. Iirc it doesn't give you exif data from dlsr images, but you can use the PIL methods to get that -- though you have to end up creating an Image.

            1 Reply Last reply Reply Quote 0
            • cvp
              cvp last edited by

              I use piexif, see here

              1 Reply Last reply Reply Quote 0
              • jm2466
                jm2466 last edited by

                Thought I posted the code to merge two albums but it appears I did not. So here it is:

                import photos
                from datetime import datetime
                
                albums = photos.get_albums()
                
                # prob better ways to do this but this works, loop through albums and create list
                # where album name equals name in quotes, then take first one (should only be 1)
                sourcealbum = [a for a in albums if a.title == 'put album name here'][0]
                print(f'Nbr photos in sourcealbum: {len(sourcealbum.assets)}')
                
                sourcealbum_2 = [a for a in albums if a.title == 'put second album name here'][0]
                print(f'Nbr photos in sourcealbum_2: {len(sourcealbum_2.assets)}')
                
                # this requires that the dest album exists as it will not create it
                destalbum = [a for a in albums if a.title == 'put dest album name here']
                
                if len(destalbum) > 0:
                	destalbum = destalbum[0]
                print(f'destalbum: {destalbum}')
                
                # first create a merged list of both albums
                mergedlist = sourcealbum.assets.copy() + sourcealbum_2.assets.copy()
                
                print(f'Nbr photos in mergedlist: {len(mergedlist):,}')
                
                # sort merged list by creation date
                mergedlistsorted = sorted(mergedlist, key=lambda x: x.creation_date)
                
                # add the sorted assets to the destination album
                destalbum.add_assets(mergedlistsorted)
                
                # I always put this at the end in scripts to know for sure when it finished
                print('***** DONE *****')
                

                So this merged to albums with about 900 pics in one and 800 in another almost instantly. The resulting album had 1700+ pics in the correct order and the pics were not physically duplicated. Do not know how I could have done this any other way on the phone. I do not sync my iphone with a Mac so if I did this on Windows I would lose the live photo part of the iphone pics.

                Thanks everyone that helped!

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post
                Powered by NodeBB Forums | Contributors