py3k: Use python3 version print

This commit is contained in:
Shuge Lee 2013-01-17 14:48:20 +08:00
parent 8db7169a32
commit 1746903f82
4 changed files with 32 additions and 19 deletions

View File

@ -9,6 +9,17 @@ how to run
python crop/crop.py
## Build pillow on Ubuntu 12.04
sudo apt-get install zlib1g-dev
sudo apt-get install libjpeg8-dev
sudo apt-get install libpng12-dev
sudo apt-get install libfreetype6-dev
sudo apt-get install liblcms1-dev
sudo apt-get install python-setuptools
python setup.py build
## Build it on Mac OS X 10.6.*
Build an egg for i386 with Python 2.5/Python 2.6

View File

@ -1,4 +1,5 @@
#!/usr/bin/env python
from __future__ import print_function
import os
from PIL import Image
@ -12,9 +13,9 @@ im = im.draft("L", im.size)
w, h = im.size[0], im.size[1]
pixels = im.load()
print "width:", w
print "high:", h
print "white(255) ~ black(0):", pixels[0, 0]
print("width:", w)
print("high:", h)
print("white(255) ~ black(0):", pixels[0, 0])
def print_im(im, w=None, h=None):
if isinstance(im, Image.Image):
@ -27,9 +28,9 @@ def print_im(im, w=None, h=None):
for y in range(h):
if pixels[x, y] > 128:
print " ",
print(" ", end=' ')
else:
print "1",
print
print("1", end=' ')
print()
print_im(im, w, h)

View File

@ -16,20 +16,20 @@ im = Image.open(fp = file_path)
w, h = im.size[0], im.size[1]
im = im.draft("L", im.size)
pixsels = im.load()
pixels = im.load()
for x in range(w):
for y in range(h):
if pixsels[x, y] > 128:
pixsels[x, y] = WHITE
if pixels[x, y] > 128:
pixels[x, y] = WHITE
else:
pixsels[x, y] = BLACK
pixels[x, y] = BLACK
counts = []
for x in range(w):
count = len([1 for y in range(h)
if pixsels[x, y] is BLACK])
if pixels[x, y] is BLACK])
counts.append(count)
@ -38,7 +38,7 @@ hist_im = Image.new(mode="L", size=(w, h), color=WHITE)
draw = ImageDraw.Draw(hist_im)
h_step = h / max(counts)
for x in xrange(w):
for x in range(w):
left_top_x, left_top_y = x, h - counts[x] * h_step
right_bottom_x, right_bottom_y = x + 1, h
box = (left_top_x, left_top_y, right_bottom_x, right_bottom_y)

View File

@ -1,4 +1,5 @@
#!/usr/bin/env python
from __future__ import print_function
import os
from PIL import Image
@ -11,13 +12,13 @@ file_path = os.path.join(parent_path, "image_resources", "captcha.jpg")
im = Image.open(fp=file_path)
w, h = im.size[0], im.size[1]
print "format:", type(im.format), im.format
print "info:", type(im.info), im.info
print "mode:", type(im.mode), im.mode
print "size:", type(im.size), im.size
print "bands:", type(im.getbands()), im.getbands()
print "histogram:", type(im.histogram())
print("format:", type(im.format), im.format)
print("info:", type(im.info), im.info)
print("mode:", type(im.mode), im.mode)
print("size:", type(im.size), im.size)
print("bands:", type(im.getbands()), im.getbands())
print("histogram:", type(im.histogram()))
data = im.getdata()
print "getdata:", type(data)
print("getdata:", type(data))
assert len(im.getdata()) == w * h