Commits

Takayuki KONDO committed 7bbb256

PIL 追加

Comments (0)

Files changed (3)

+===================================
+PIL (Python Image Library)
+===================================
+
+環境準備
+==========
+
+* Python 2.7.3 (x86)
+* Windows 7 Professional
+
+結論
+-------
+* PILをバイナリインストーラからインストールすること。
+
+
+pip でインストールした場合のエラー
+--------------------------------------
+
+Windows 環境の場合、 pip install pil でインストールしても
+下記エラーが発生する。
+
+::
+ 
+    --------------------------------------------------------------------
+    PIL 1.1.7 SETUP SUMMARY
+    --------------------------------------------------------------------
+    version       1.1.7
+    platform      win32 2.7.3 (default, Apr 10 2012, 23:31:26)
+                  [MSC v.1500 32 bit (Intel)]
+    --------------------------------------------------------------------
+    *** TKINTER support not available (Tcl/Tk 8.5 libraries needed)
+    *** JPEG support not available
+    *** ZLIB (PNG/ZIP) support not available
+    *** FREETYPE2 support not available
+    *** LITTLECMS support not available
+    --------------------------------------------------------------------
+    To add a missing option, make sure you have the required
+    library, and set the corresponding ROOT variable in the
+    setup.py script.
+
+    To check the build, run the selftest.py script.
+
+ Successfully installed pil
+ Cleaning up...
+
+
+Windows PIL
+==================
+
+しかたないので、Windows のバイナリをダウンロードしてみる。
+
+http://effbot.org/downloads/PIL-1.1.7.win32-py2.7.exe
+
+pip uninstall pil を実行し、
+
+ダウンロードした exe にてインストール実施。
+
+./mandelbrot.py を実行して、 mandel.png ができていることを確認
+
+x
+#!/usr/bin/env python
+
+import Image
+import ImageDraw
+
+img = Image.new('RGB', (100,100), (255, 255, 255))
+draw = ImageDraw.Draw(img)
+draw.point([(i, i*2) for i in range(20)], (0, 255, 255))
+
+img.save('image.jpg', 'JPEG')
+img.save('image.png', 'PNG')
+

PIL/mandelbrot.py

+#!/usr/bin/env python
+## {{{ http://code.activestate.com/recipes/577111/ (r2)
+# Mandelbrot fractal
+# FB - 201003254
+from PIL import Image
+# drawing area
+xa = -2.0
+xb = 1.0
+ya = -1.5
+yb = 1.5
+maxIt = 255 # max iterations allowed
+# image size
+imgx = 512
+imgy = 512
+image = Image.new("RGB", (imgx, imgy))
+
+for y in range(imgy):
+    zy = y * (yb - ya) / (imgy - 1)  + ya
+    for x in range(imgx):
+        zx = x * (xb - xa) / (imgx - 1)  + xa
+        z = zx + zy * 1j
+        c = z
+        for i in range(maxIt):
+            if abs(z) > 2.0: break 
+            z = z * z + c
+        image.putpixel((x, y), (i % 4 * 64, i % 8 * 32, i % 16 * 16))
+
+image.save("mandel.png", "PNG")
+## end of http://code.activestate.com/recipes/577111/ }}}