From 1746903f822dd93a66ea8c28b571fef7dd07e0ba Mon Sep 17 00:00:00 2001 From: Shuge Lee Date: Thu, 17 Jan 2013 14:48:20 +0800 Subject: [PATCH] py3k: Use python3 version print --- Demos/README.md | 11 +++++++++++ Demos/access_pixels/access_pixels.py | 13 +++++++------ Demos/histogram/histogram.py | 12 ++++++------ Demos/image_info/get_img_info.py | 15 ++++++++------- 4 files changed, 32 insertions(+), 19 deletions(-) diff --git a/Demos/README.md b/Demos/README.md index 47c869ffd..2617677ca 100644 --- a/Demos/README.md +++ b/Demos/README.md @@ -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 diff --git a/Demos/access_pixels/access_pixels.py b/Demos/access_pixels/access_pixels.py index eae87c85e..fb9ccfcae 100644 --- a/Demos/access_pixels/access_pixels.py +++ b/Demos/access_pixels/access_pixels.py @@ -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) \ No newline at end of file diff --git a/Demos/histogram/histogram.py b/Demos/histogram/histogram.py index a79d579ea..90a00b5e5 100644 --- a/Demos/histogram/histogram.py +++ b/Demos/histogram/histogram.py @@ -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) diff --git a/Demos/image_info/get_img_info.py b/Demos/image_info/get_img_info.py index e713f0f4b..fc59b025c 100644 --- a/Demos/image_info/get_img_info.py +++ b/Demos/image_info/get_img_info.py @@ -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