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?
-
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!
-
-
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) -
-
@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)
-
Thank you! This is very helpful!
-
-
@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()