Pythonistaで処理した画像をiOSの写真に追加したい
サンプルコード
sample.py
import photos
import os
import tempfile
from PIL import Image
imageName = 'lena.png'
img = Image.open(imageName)
temp_path = os.path.join(tempfile.gettempdir(),imageName)
img.save(temp_path)
photos.create_image_asset(temp_path)
解説
画像を追加する関数はphotos.create_image_asset()
なのですが、どこかに画像が保存されていないといけないので、temp_path
を取得し、一旦そこに保存しているよって感じです。
スクリプトがあるディレクトリと同じところに一旦保存するよりもなんとなくスマートですね。