• @jm2466 this

    # 1) convert PIL Image to ui.Image console.hud_alert('convert PIL Image into ui.Image') with io.BytesIO() as bIO: new_im.save(bIO, 'PNG') ui_image = ui.Image.from_data(bIO.getvalue()) del bIO # 2) Create a PHAsset from an ui.Image (not from a PIL Image) console.hud_alert('Create a PHAsset from an ui.Image') lib = PHPhotoLibrary.sharedPhotoLibrary() def change_block(): req = PHAssetChangeRequest.creationRequestForAssetFromImage_(ui_image) def perform_changes(): lib.performChangesAndWait_error_(change_block, None) t = threading.Thread(target=perform_changes) t.start() t.join()

    is about (😀) 1000 x slower than

    path = 'temp.jpg' new_im.save(path , quality=95) photos.create_image_asset(path) os.remove(path)
  • 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!

  • @JonB, I am on 11.2.6 and get a crash with ”Fatal Python error: Aborted” at HomeManager init, delegate init is fine.

  • A similar problem (how to get a photo library asset object from a share sheet image) was recently discussed here : https://forum.omz-software.com/topic/4101/using-appex-to-modify-a-photo-creation-date-directly

Internal error.

Oops! Looks like something went wrong!