python
%pylab inline
from PIL import Image,ImageDraw,ImageFont
#Create an image
img = Image.new('RGB', (800,200),(255,255,255)) # 800*200 white background
#Edit image
draw = ImageDraw.Draw(img)
draw.line((0, 0, 799, 199),fill='green') #Green straight line
pl_img = np.array(img) ; plt.imshow( pl_img ) #display
FONTPATH = '/usr/share/fonts/truetype/fonts-japanese-gothic.ttf'
font = ImageFont.truetype(FONTPATH, 24, encoding='utf-8')
draw.text((40,80),'Test test test test',font=font, fill='black')
pl_img = np.array(img) ; plt.imshow( pl_img ) #display
#Save image
img.save('test_draw.png')
I can say it myself, but it's not very interesting.
↓ I tried to raise the notebook here nbviewer.ipython.org/github/suto3/git-public/blob/master/python/notebook/Pillow-workflow01.ipynb
↓ Click here for the working environment Pillow environment construction --Virtual environment by virtualenv, interactive environment by iPython --Qiita
Try using Pillow on iPython (Part 2) --Qiita
Try Pillow on iPython (Part 3) --Qiita
Recommended Posts