LoginSignup
2

More than 5 years have passed since last update.

iPython上でPillowを使ってみる(その1)

Last updated at Posted at 2015-03-21

Pillowの作業フロー(その1)

  1. Image.new で画像を作成する
  2. ImageDraw等で画像をゴニョゴニョする
  3. Image.save で編集した画像を保存する

実例

sc-20150321.PNG

%pylab inline
from PIL import Image,ImageDraw,ImageFont

# 画像を作成
img = Image.new('RGB', (800,200),(255,255,255)) # 800*200の白背景

# 画像を編集
draw = ImageDraw.Draw(img) 
draw.line((0, 0, 799, 199),fill='green') # 緑の直線

pl_img = np.array(img) ; plt.imshow( pl_img ) # 表示

FONTPATH = '/usr/share/fonts/truetype/fonts-japanese-gothic.ttf'
font = ImageFont.truetype(FONTPATH, 24, encoding='utf-8')
draw.text((40,80),'Test テスト test 試験',font=font, fill='black') 

pl_img = np.array(img) ; plt.imshow( pl_img ) # 表示

# 画像を保存
img.save('test_draw.png') 

自分で言うのもなんだが、あんまりおもしろくないな。

↓ノートブックをこっちに上げてみました
nbviewer.ipython.org/github/suto3/git-public/blob/master/python/notebook/Pillow-workflow01.ipynb

↓作業環境については、こちら
Pillow環境構築 -- virtualenvによる仮想環境、iPythonによるインタラクティブ環境 - Qiita

iPython上でPillowを使ってみる(その2) - Qiita

iPython上でPillowを使ってみる(その3) - Qiita

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
2