Pythonistaで利用できる photos モジュール 触ってみた。
■参考サイト
photos — Photo Library Access on iOS
■検証時に使用したコード
import photos as ph
#Get the last photo, and show it in the concole
def show_last_asset():
all_assets = ph.get_assets()
last_asset = all_assets[-1]
img = last_asset.get_image()
#img = last_asset.get_ui_image()
img.show()
#Get the oldest screenshot image, and delete it from the library
def show_oldest_screenshot_delete():
album = ph.get_screenshots_album()
screenshots = album.assets
if not screenshots:
print("You have no screenshots in your library.")
else:
oldest = screenshots[0]
if oldest.can_delete:
#This will automatically show a confirmation dialog:
#削除して良いかのダイアログが自動的に表示される
oldest.delete()
else:
print("Oldest screenshot is not deletable")
#Get the last photo, and convert it to grayscale, saving the edit in-place
def convert_grayscale():
album = ph.get_recently_added_album()
last = album.assets[-1]
if last.can_edit_content:
img = last.get_image()
grayscale_img = img.convert("L") #グレーへの色変更
grayscale_img.save(".edit.jpg", quality=90)
last.edit_content(".edit.jpg")
else:
print("The asset is not editable")
#Show an image picker dialog (allowing multiple selection) and print the result
def image_picker():
assets = ph.pick_asset(assets=ph.get_assets(), title="Pick some assets", multi=True)
print(assets)
■感想
iOSのフォトライブラリにアクセスして、いろいろ操作することができるのはとても便利。
アセットのサイズによって多少動作が遅かったりしたのがちょっと残念。
もし、アプリ開発とかするのであれば、負荷とかをいろいろと考慮しないといけないと思う。