3
4

More than 3 years have passed since last update.

PythonistaでiOSの写真に画像を追加する

Posted at

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を取得し、一旦そこに保存しているよって感じです。

スクリプトがあるディレクトリと同じところに一旦保存するよりもなんとなくスマートですね。

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4