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.


    How to use create_image_asset for downloaded image instead of save_image since it does not accept PIL image?

    Pythonista
    2
    8
    4608
    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.
    • idchlife
      idchlife last edited by idchlife

      I see that photos.save_image became deprecated, so I tried using create_image_asset, but it does not work with image urls or PIL image that was created by downloading url: Image.open(BytesIO(urlopen(photo_url).read()))

      How .save_image could be deprecated, if not tool available to replace it?

      Thanks!

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

        @idchlife see here

        1 Reply Last reply Reply Quote 1
        • idchlife
          idchlife last edited by

          Tried it and it works! Thanks!

          Any info or idea why .save_image with functionality making image from data was depreacted?
          It seems unreasonable to save temporary file to app folder just to have it inside photos duplicated (of course temporary file could be deleted after)

          cvp 2 Replies Last reply Reply Quote 0
          • cvp
            cvp @idchlife last edited by

            @idchlife No idea, sorry, hoping @omz will answer to you

            1 Reply Last reply Reply Quote 1
            • cvp
              cvp @idchlife last edited by

              @idchlife Try this

              # img is a PIL image
              with tempfile.NamedTemporaryFile(suffix='.jpg') as temp:
              	img.save(temp.name, format="JPEG")
              	photos.create_image_asset(temp.name)
              
              1 Reply Last reply Reply Quote 1
              • idchlife
                idchlife last edited by

                Thank you! This is very helpful!

                cvp 2 Replies Last reply Reply Quote 0
                • cvp
                  cvp @idchlife last edited by cvp

                  @idchlife read this and it's important paragraph
                  I think the save of a pil or ui. Image is deprecated because in this case, you only save the image, not its metadata, as described in Apple doc

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

                    @idchlife If you really want to create a photo from an ui.Image without passing via a temporary file, you can use Objective-C but it it is not a nice code 😂

                    # only to have an ui.Image
                    import ui
                    img = ui.Image.named('test:Bridge')
                    
                    # Create a PHAsset from an ui.Image (not from a PIL Image)
                    from objc_util import *
                    import threading
                    
                    NSBundle.bundleWithPath_('/System/Library/Frameworks/Photos.framework').load()
                    PHPhotoLibrary = ObjCClass('PHPhotoLibrary')
                    PHAssetChangeRequest = ObjCClass('PHAssetChangeRequest')
                    
                    lib = PHPhotoLibrary.sharedPhotoLibrary()
                    def change_block():
                    	req = PHAssetChangeRequest.creationRequestForAssetFromImage_(img)
                    def perform_changes():
                    	lib.performChangesAndWait_error_(change_block, None)
                    
                    t = threading.Thread(target=perform_changes)
                    t.start()
                    t.join()
                    
                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post
                    Powered by NodeBB Forums | Contributors