py3k: print is a function

Seriously, if you didn't know that, you've been in a freaking cave, man.
This commit is contained in:
Brian Crowell 2012-10-15 21:27:35 -05:00 committed by Brian Crowell
parent aeab3f5911
commit 5076c35cc5
23 changed files with 198 additions and 153 deletions

View File

@ -18,6 +18,8 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from __future__ import print_function
__version__ = "0.4" __version__ = "0.4"
import Image, ImageFile, ImagePalette import Image, ImageFile, ImagePalette
@ -70,8 +72,8 @@ class ArgStream(ChunkStream):
raise SyntaxError("unknown ARG mode") raise SyntaxError("unknown ARG mode")
if Image.DEBUG: if Image.DEBUG:
print "AHDR size", self.size print("AHDR size", self.size)
print "AHDR mode", self.mode, self.rawmode print("AHDR mode", self.mode, self.rawmode)
return s return s
@ -98,7 +100,7 @@ class ArgStream(ChunkStream):
self.repair = None self.repair = None
if Image.DEBUG: if Image.DEBUG:
print "AFRM", self.id, self.count print("AFRM", self.id, self.count)
return s return s
@ -121,7 +123,7 @@ class ArgStream(ChunkStream):
self.count = i16(s[2:4]) self.count = i16(s[2:4])
if Image.DEBUG: if Image.DEBUG:
print "ADEF", self.id, self.count print("ADEF", self.id, self.count)
return s return s
@ -141,7 +143,7 @@ class ArgStream(ChunkStream):
"AEND -- end of animation" "AEND -- end of animation"
if Image.DEBUG: if Image.DEBUG:
print "AEND" print("AEND")
self.eof = 1 self.eof = 1
@ -256,7 +258,7 @@ class ArgStream(ChunkStream):
bbox = offs + (offs[0]+size[0], offs[1]+size[1]) bbox = offs + (offs[0]+size[0], offs[1]+size[1])
if Image.DEBUG: if Image.DEBUG:
print "DHDR", diff, bbox print("DHDR", diff, bbox)
# FIXME: decode and apply image # FIXME: decode and apply image
self.action = ("DHDR", diff, bbox) self.action = ("DHDR", diff, bbox)
@ -473,7 +475,7 @@ class ArgImageFile(ImageFile.ImageFile):
except "glurk": # AttributeError except "glurk": # AttributeError
if Image.DEBUG: if Image.DEBUG:
print cid, bytes, "(unknown)" print(cid, bytes, "(unknown)")
s = self.fp.read(bytes) s = self.fp.read(bytes)
self.arg.crc(cid, s) self.arg.crc(cid, s)

View File

@ -24,6 +24,8 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from __future__ import print_function
VERSION = "1.1.7" VERSION = "1.1.7"
try: try:
@ -355,8 +357,8 @@ def init():
del sys.path[0] del sys.path[0]
except ImportError: except ImportError:
if DEBUG: if DEBUG:
print "Image: failed to import", print("Image: failed to import", end=' ')
print f, ":", sys.exc_info()[1] print(f, ":", sys.exc_info()[1])
visited[fullpath] = None visited[fullpath] = None
if OPEN or SAVE: if OPEN or SAVE:

View File

@ -15,6 +15,8 @@
# below for the original description. # below for the original description.
# #
from __future__ import print_function
DESCRIPTION = """ DESCRIPTION = """
pyCMS pyCMS
@ -770,16 +772,16 @@ if __name__ == "__main__":
# create a cheap manual from the __doc__ strings for the functions above # create a cheap manual from the __doc__ strings for the functions above
import ImageCms import ImageCms
print __doc__ print(__doc__)
for f in dir(pyCMS): for f in dir(pyCMS):
print "="*80 print("="*80)
print "%s" %f print("%s" %f)
try: try:
exec ("doc = ImageCms.%s.__doc__" %(f)) exec ("doc = ImageCms.%s.__doc__" %(f))
if "pyCMS" in doc: if "pyCMS" in doc:
# so we don't get the __doc__ string for imported modules # so we don't get the __doc__ string for imported modules
print doc print(doc)
except AttributeError: except AttributeError:
pass pass

View File

@ -25,6 +25,8 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from __future__ import print_function
import Image import Image
import os, sys import os, sys
@ -381,10 +383,10 @@ if __name__ == "__main__":
# create font data chunk for embedding # create font data chunk for embedding
import base64, os, sys import base64, os, sys
font = "../Images/courB08" font = "../Images/courB08"
print " f._load_pilfont_data(" print(" f._load_pilfont_data(")
print " # %s" % os.path.basename(font) print(" # %s" % os.path.basename(font))
print " StringIO(base64.decodestring('''" print(" StringIO(base64.decodestring('''")
base64.encode(open(font + ".pil", "rb"), sys.stdout) base64.encode(open(font + ".pil", "rb"), sys.stdout)
print "''')), Image.open(StringIO(base64.decodestring('''" print("''')), Image.open(StringIO(base64.decodestring('''")
base64.encode(open(font + ".pbm", "rb"), sys.stdout) base64.encode(open(font + ".pbm", "rb"), sys.stdout)
print "'''))))" print("'''))))")

View File

@ -12,6 +12,8 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from __future__ import print_function
import Image import Image
import os, sys import os, sys
@ -160,4 +162,4 @@ else:
if __name__ == "__main__": if __name__ == "__main__":
# usage: python ImageShow.py imagefile [title] # usage: python ImageShow.py imagefile [title]
print show(Image.open(sys.argv[1]), *sys.argv[2:]) print(show(Image.open(sys.argv[1]), *sys.argv[2:]))

View File

@ -15,6 +15,7 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from __future__ import print_function
__version__ = "0.3" __version__ = "0.3"
@ -44,8 +45,8 @@ def i(c):
def dump(c): def dump(c):
for i in c: for i in c:
print "%02x" % ord(i), print("%02x" % ord(i), end=' ')
print print()
## ##
# Image plugin for IPTC/NAA datastreams. To read IPTC/NAA fields # Image plugin for IPTC/NAA datastreams. To read IPTC/NAA fields

View File

@ -36,6 +36,8 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from __future__ import print_function
import StringIO import StringIO
import sys import sys
@ -208,12 +210,12 @@ class _OleDirectoryEntry:
TYPES = ["(invalid)", "(storage)", "(stream)", "(lockbytes)", TYPES = ["(invalid)", "(storage)", "(stream)", "(lockbytes)",
"(property)", "(root)"] "(property)", "(root)"]
print " "*tab + repr(self.name), TYPES[self.type], print(" "*tab + repr(self.name), TYPES[self.type], end=' ')
if self.type in (2, 5): if self.type in (2, 5):
print self.size, "bytes", print(self.size, "bytes", end=' ')
print print()
if self.type in (1, 5) and self.clsid: if self.type in (1, 5) and self.clsid:
print " "*tab + "{%s}" % self.clsid print(" "*tab + "{%s}" % self.clsid)
for kid in self.kids: for kid in self.kids:
kid.dump(tab + 2) kid.dump(tab + 2)
@ -515,17 +517,17 @@ if __name__ == "__main__":
for file in sys.argv[1:]: for file in sys.argv[1:]:
try: try:
ole = OleFileIO(file) ole = OleFileIO(file)
print "-" * 68 print("-" * 68)
print file print(file)
print "-" * 68 print("-" * 68)
ole.dumpdirectory() ole.dumpdirectory()
for file in ole.listdir(): for file in ole.listdir():
if file[-1][0] == "\005": if file[-1][0] == "\005":
print file print(file)
props = ole.getproperties(file) props = ole.getproperties(file)
props = list(props.items()) props = list(props.items())
props.sort() props.sort()
for k, v in props: for k, v in props:
print " ", k, v print(" ", k, v)
except IOError as v: except IOError as v:
print "***", "cannot read", file, "-", v print("***", "cannot read", file, "-", v)

View File

@ -15,6 +15,8 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from __future__ import print_function
import EpsImagePlugin import EpsImagePlugin
## ##
@ -60,7 +62,7 @@ class PSDraw:
self.fp.write("/F0 %d /PSDraw-%s F\n" % (size, font)) self.fp.write("/F0 %d /PSDraw-%s F\n" % (size, font))
def setink(self, ink): def setink(self, ink):
print "*** NOT YET IMPLEMENTED ***" print("*** NOT YET IMPLEMENTED ***")
def line(self, xy0, xy1): def line(self, xy0, xy1):
xy = xy0 + xy1 xy = xy0 + xy1

View File

@ -31,6 +31,8 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from __future__ import print_function
__version__ = "0.9" __version__ = "0.9"
import re import re
@ -111,7 +113,7 @@ class ChunkStream:
"Call the appropriate chunk handler" "Call the appropriate chunk handler"
if Image.DEBUG: if Image.DEBUG:
print "STREAM", cid, pos, len print("STREAM", cid, pos, len)
return getattr(self, "chunk_" + cid)(pos, len) return getattr(self, "chunk_" + cid)(pos, len)
def crc(self, cid, data): def crc(self, cid, data):
@ -191,8 +193,8 @@ class PngStream(ChunkStream):
# Compressed profile n bytes (zlib with deflate compression) # Compressed profile n bytes (zlib with deflate compression)
i = s.find(chr(0)) i = s.find(chr(0))
if Image.DEBUG: if Image.DEBUG:
print "iCCP profile name", s[:i] print("iCCP profile name", s[:i])
print "Compression method", ord(s[i]) print("Compression method", ord(s[i]))
comp_method = ord(s[i]) comp_method = ord(s[i])
if comp_method != 0: if comp_method != 0:
raise SyntaxError("Unknown compression method %s in iCCP chunk" % comp_method) raise SyntaxError("Unknown compression method %s in iCCP chunk" % comp_method)
@ -333,7 +335,7 @@ class PngImageFile(ImageFile.ImageFile):
break break
except AttributeError: except AttributeError:
if Image.DEBUG: if Image.DEBUG:
print cid, pos, len, "(unknown)" print(cid, pos, len, "(unknown)")
s = ImageFile._safe_read(self.fp, len) s = ImageFile._safe_read(self.fp, len)
self.png.crc(cid, s) self.png.crc(cid, s)

View File

@ -33,6 +33,8 @@
# http://www.wadsworth.org/spider_doc/spider/docs/image_doc.html # http://www.wadsworth.org/spider_doc/spider/docs/image_doc.html
# #
from __future__ import print_function
import Image, ImageFile import Image, ImageFile
import os, struct, sys import os, struct, sys
@ -186,13 +188,13 @@ def loadImageSeries(filelist=None):
imglist = [] imglist = []
for img in filelist: for img in filelist:
if not os.path.exists(img): if not os.path.exists(img):
print "unable to find %s" % img print("unable to find %s" % img)
continue continue
try: try:
im = Image.open(img).convert2byte() im = Image.open(img).convert2byte()
except: except:
if not isSpiderImage(img): if not isSpiderImage(img):
print img + " is not a Spider image file" print(img + " is not a Spider image file")
continue continue
im.info['filename'] = img im.info['filename'] = img
imglist.append(im) imglist.append(im)
@ -267,12 +269,12 @@ Image.register_save("SPIDER", _save_spider)
if __name__ == "__main__": if __name__ == "__main__":
if not sys.argv[1:]: if not sys.argv[1:]:
print "Syntax: python SpiderImagePlugin.py Spiderimage [outfile]" print("Syntax: python SpiderImagePlugin.py Spiderimage [outfile]")
sys.exit() sys.exit()
filename = sys.argv[1] filename = sys.argv[1]
if not isSpiderImage(filename): if not isSpiderImage(filename):
print "input image must be in Spider format" print("input image must be in Spider format")
sys.exit() sys.exit()
outfile = "" outfile = ""
@ -280,15 +282,15 @@ if __name__ == "__main__":
outfile = sys.argv[2] outfile = sys.argv[2]
im = Image.open(filename) im = Image.open(filename)
print "image: " + str(im) print("image: " + str(im))
print "format: " + str(im.format) print("format: " + str(im.format))
print "size: " + str(im.size) print("size: " + str(im.size))
print "mode: " + str(im.mode) print("mode: " + str(im.mode))
print "max, min: ", print("max, min: ", end=' ')
print im.getextrema() print(im.getextrema())
if outfile != "": if outfile != "":
# perform some image operation # perform some image operation
im = im.transpose(Image.FLIP_LEFT_RIGHT) im = im.transpose(Image.FLIP_LEFT_RIGHT)
print "saving a flipped version of %s as %s " % (os.path.basename(filename), outfile) print("saving a flipped version of %s as %s " % (os.path.basename(filename), outfile))
im.save(outfile, "SPIDER") im.save(outfile, "SPIDER")

View File

@ -39,6 +39,8 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from __future__ import print_function
__version__ = "1.3.5" __version__ = "1.3.5"
import Image, ImageFile import Image, ImageFile
@ -352,14 +354,14 @@ class ImageFileDirectory(collections.MutableMapping):
import TiffTags import TiffTags
tagname = TiffTags.TAGS.get(tag, "unknown") tagname = TiffTags.TAGS.get(tag, "unknown")
typname = TiffTags.TYPES.get(typ, "unknown") typname = TiffTags.TYPES.get(typ, "unknown")
print "tag: %s (%d)" % (tagname, tag), print("tag: %s (%d)" % (tagname, tag), end=' ')
print "- type: %s (%d)" % (typname, typ), print("- type: %s (%d)" % (typname, typ), end=' ')
try: try:
dispatch = self.load_dispatch[typ] dispatch = self.load_dispatch[typ]
except KeyError: except KeyError:
if Image.DEBUG: if Image.DEBUG:
print "- unsupported type", typ print("- unsupported type", typ)
continue # ignore unsupported type continue # ignore unsupported type
size, handler = dispatch size, handler = dispatch
@ -383,9 +385,9 @@ class ImageFileDirectory(collections.MutableMapping):
if Image.DEBUG: if Image.DEBUG:
if tag in (COLORMAP, IPTC_NAA_CHUNK, PHOTOSHOP_CHUNK, ICCPROFILE, XMP): if tag in (COLORMAP, IPTC_NAA_CHUNK, PHOTOSHOP_CHUNK, ICCPROFILE, XMP):
print "- value: <table: %d bytes>" % size print("- value: <table: %d bytes>" % size)
else: else:
print "- value:", self[tag] print("- value:", self[tag])
self.next = i32(fp.read(4)) self.next = i32(fp.read(4))
@ -449,13 +451,13 @@ class ImageFileDirectory(collections.MutableMapping):
import TiffTags import TiffTags
tagname = TiffTags.TAGS.get(tag, "unknown") tagname = TiffTags.TAGS.get(tag, "unknown")
typname = TiffTags.TYPES.get(typ, "unknown") typname = TiffTags.TYPES.get(typ, "unknown")
print "save: %s (%d)" % (tagname, tag), print("save: %s (%d)" % (tagname, tag), end=' ')
print "- type: %s (%d)" % (typname, typ), print("- type: %s (%d)" % (typname, typ), end=' ')
if tag in (COLORMAP, IPTC_NAA_CHUNK, PHOTOSHOP_CHUNK, ICCPROFILE, XMP): if tag in (COLORMAP, IPTC_NAA_CHUNK, PHOTOSHOP_CHUNK, ICCPROFILE, XMP):
size = len(data) size = len(data)
print "- value: <table: %d bytes>" % size print("- value: <table: %d bytes>" % size)
else: else:
print "- value:", value print("- value:", value)
# figure out if data fits into the directory # figure out if data fits into the directory
if len(data) == 4: if len(data) == 4:
@ -481,7 +483,7 @@ class ImageFileDirectory(collections.MutableMapping):
# pass 2: write directory to file # pass 2: write directory to file
for tag, typ, count, value, data in directory: for tag, typ, count, value, data in directory:
if Image.DEBUG > 1: if Image.DEBUG > 1:
print tag, typ, count, repr(value), repr(data) print(tag, typ, count, repr(value), repr(data))
fp.write(o16(tag) + o16(typ) + o32(count) + value) fp.write(o16(tag) + o16(typ) + o32(count) + value)
# -- overwrite here for multi-page -- # -- overwrite here for multi-page --
@ -601,11 +603,11 @@ class TiffImageFile(ImageFile.ImageFile):
fillorder = getscalar(FILLORDER, 1) fillorder = getscalar(FILLORDER, 1)
if Image.DEBUG: if Image.DEBUG:
print "*** Summary ***" print("*** Summary ***")
print "- compression:", self._compression print("- compression:", self._compression)
print "- photometric_interpretation:", photo print("- photometric_interpretation:", photo)
print "- planar_configuration:", self._planar_configuration print("- planar_configuration:", self._planar_configuration)
print "- fill_order:", fillorder print("- fill_order:", fillorder)
# size # size
xsize = getscalar(IMAGEWIDTH) xsize = getscalar(IMAGEWIDTH)
@ -613,7 +615,7 @@ class TiffImageFile(ImageFile.ImageFile):
self.size = xsize, ysize self.size = xsize, ysize
if Image.DEBUG: if Image.DEBUG:
print "- size:", self.size print("- size:", self.size)
format = getscalar(SAMPLEFORMAT, 1) format = getscalar(SAMPLEFORMAT, 1)
@ -624,17 +626,17 @@ class TiffImageFile(ImageFile.ImageFile):
self.tag.get(EXTRASAMPLES, ()) self.tag.get(EXTRASAMPLES, ())
) )
if Image.DEBUG: if Image.DEBUG:
print "format key:", key print("format key:", key)
try: try:
self.mode, rawmode = OPEN_INFO[key] self.mode, rawmode = OPEN_INFO[key]
except KeyError: except KeyError:
if Image.DEBUG: if Image.DEBUG:
print "- unsupported format" print("- unsupported format")
raise SyntaxError("unknown pixel mode") raise SyntaxError("unknown pixel mode")
if Image.DEBUG: if Image.DEBUG:
print "- raw mode:", rawmode print("- raw mode:", rawmode)
print "- pil mode:", self.mode print("- pil mode:", self.mode)
self.info["compression"] = self._compression self.info["compression"] = self._compression
@ -695,7 +697,7 @@ class TiffImageFile(ImageFile.ImageFile):
a = None a = None
else: else:
if Image.DEBUG: if Image.DEBUG:
print "- unsupported data organization" print("- unsupported data organization")
raise SyntaxError("unknown data organization") raise SyntaxError("unknown data organization")
# fixup palette descriptor # fixup palette descriptor

View File

@ -21,6 +21,8 @@
# http://www.flipcode.com/tutorials/tut_q2levels.shtml # http://www.flipcode.com/tutorials/tut_q2levels.shtml
# and has been tested with a few sample files found using google. # and has been tested with a few sample files found using google.
from __future__ import print_function
import Image import Image
def i32(c, o=0): def i32(c, o=0):
@ -122,5 +124,5 @@ quake2palette = (
if __name__ == "__main__": if __name__ == "__main__":
im = open("../hacks/sample.wal") im = open("../hacks/sample.wal")
print im.info, im.mode, im.size print(im.info, im.mode, im.size)
im.save("../out.png") im.save("../out.png")

View File

@ -4,6 +4,8 @@
# Shows how to scan a 16 bit grayscale image into a numarray object # Shows how to scan a 16 bit grayscale image into a numarray object
# #
from __future__ import print_function
# Get the path set up to find PIL modules if not installed yet: # Get the path set up to find PIL modules if not installed yet:
import sys ; sys.path.append('../PIL') import sys ; sys.path.append('../PIL')
@ -23,8 +25,8 @@ def toImage(arr):
im = Image.fromstring('L', arr.shape[::-1], arr.tostring()) im = Image.fromstring('L', arr.shape[::-1], arr.tostring())
return im return im
print 'SANE version:', sane.init() print('SANE version:', sane.init())
print 'Available devices=', sane.get_devices() print('Available devices=', sane.get_devices())
s = sane.open(sane.get_devices()[0][0]) s = sane.open(sane.get_devices()[0][0])
@ -32,7 +34,7 @@ s = sane.open(sane.get_devices()[0][0])
s.mode = 'gray' s.mode = 'gray'
s.br_x=320. ; s.br_y=240. s.br_x=320. ; s.br_y=240.
print 'Device parameters:', s.get_parameters() print('Device parameters:', s.get_parameters())
s.depth=16 s.depth=16
arr16 = s.arr_scan() arr16 = s.arr_scan()

View File

@ -4,19 +4,21 @@
# Shows how to scan a color image into a PIL rgb-image # Shows how to scan a color image into a PIL rgb-image
# #
from __future__ import print_function
# Get the path set up to find PIL modules if not installed yet: # Get the path set up to find PIL modules if not installed yet:
import sys ; sys.path.append('../PIL') import sys ; sys.path.append('../PIL')
import sane import sane
print 'SANE version:', sane.init() print('SANE version:', sane.init())
print 'Available devices=', sane.get_devices() print('Available devices=', sane.get_devices())
s = sane.open(sane.get_devices()[0][0]) s = sane.open(sane.get_devices()[0][0])
s.mode = 'color' s.mode = 'color'
s.br_x=320. ; s.br_y=240. s.br_x=320. ; s.br_y=240.
print 'Device parameters:', s.get_parameters() print('Device parameters:', s.get_parameters())
# Initiate the scan # Initiate the scan
s.start() s.start()

View File

@ -5,6 +5,8 @@
# split an animation into a number of frame files # split an animation into a number of frame files
# #
from __future__ import print_function
from PIL import Image from PIL import Image
import os, sys import os, sys
@ -53,17 +55,17 @@ if sys.argv[1:2] == ["-h"]:
del sys.argv[1] del sys.argv[1]
if not sys.argv[2:]: if not sys.argv[2:]:
print print()
print "Syntax: python explode.py infile template [range]" print("Syntax: python explode.py infile template [range]")
print print()
print "The template argument is used to construct the names of the" print("The template argument is used to construct the names of the")
print "individual frame files. The frames are numbered file001.ext," print("individual frame files. The frames are numbered file001.ext,")
print "file002.ext, etc. You can insert %d to control the placement" print("file002.ext, etc. You can insert %d to control the placement")
print "and syntax of the frame number." print("and syntax of the frame number.")
print print()
print "The optional range argument specifies which frames to extract." print("The optional range argument specifies which frames to extract.")
print "You can give one or more ranges like 1-10, 5, -15 etc. If" print("You can give one or more ranges like 1-10, 5, -15 etc. If")
print "omitted, all frames are extracted." print("omitted, all frames are extracted.")
sys.exit(1) sys.exit(1)
infile = sys.argv[1] infile = sys.argv[1]
@ -91,7 +93,7 @@ while 1:
if frames[ix]: if frames[ix]:
im.save(outfile % ix) im.save(outfile % ix)
print outfile % ix print(outfile % ix)
if html: if html:
html.write("<img src='%s'><br>\n" % outfile % ix) html.write("<img src='%s'><br>\n" % outfile % ix)

View File

@ -39,6 +39,8 @@
# write data directly to a socket. Or something... # write data directly to a socket. Or something...
# #
from __future__ import print_function
from PIL import Image, ImageChops from PIL import Image, ImageChops
from PIL.GifImagePlugin import getheader, getdata from PIL.GifImagePlugin import getheader, getdata
@ -127,8 +129,8 @@ if __name__ == "__main__":
import sys import sys
if len(sys.argv) < 3: if len(sys.argv) < 3:
print "GIFMAKER -- create GIF animations" print("GIFMAKER -- create GIF animations")
print "Usage: gifmaker infile outfile" print("Usage: gifmaker infile outfile")
sys.exit(1) sys.exit(1)
compress(sys.argv[1], sys.argv[2]) compress(sys.argv[1], sys.argv[2])

View File

@ -13,27 +13,29 @@
# 0.5 98-12-30 fl Fixed -f option (from Anthony Baxter) # 0.5 98-12-30 fl Fixed -f option (from Anthony Baxter)
# #
from __future__ import print_function
import site import site
import getopt, string, sys import getopt, string, sys
from PIL import Image from PIL import Image
def usage(): def usage():
print "PIL Convert 0.5/1998-12-30 -- convert image files" print("PIL Convert 0.5/1998-12-30 -- convert image files")
print "Usage: pilconvert [option] infile outfile" print("Usage: pilconvert [option] infile outfile")
print print()
print "Options:" print("Options:")
print print()
print " -c <format> convert to format (default is given by extension)" print(" -c <format> convert to format (default is given by extension)")
print print()
print " -g convert to greyscale" print(" -g convert to greyscale")
print " -p convert to palette image (using standard palette)" print(" -p convert to palette image (using standard palette)")
print " -r convert to rgb" print(" -r convert to rgb")
print print()
print " -o optimize output (trade speed for size)" print(" -o optimize output (trade speed for size)")
print " -q <value> set compression quality (0-100, JPEG only)" print(" -q <value> set compression quality (0-100, JPEG only)")
print print()
print " -f list supported file formats" print(" -f list supported file formats")
sys.exit(1) sys.exit(1)
if len(sys.argv) == 1: if len(sys.argv) == 1:
@ -42,7 +44,7 @@ if len(sys.argv) == 1:
try: try:
opt, argv = getopt.getopt(sys.argv[1:], "c:dfgopq:r") opt, argv = getopt.getopt(sys.argv[1:], "c:dfgopq:r")
except getopt.error as v: except getopt.error as v:
print v print(v)
sys.exit(1) sys.exit(1)
format = None format = None
@ -56,12 +58,12 @@ for o, a in opt:
Image.init() Image.init()
id = Image.ID[:] id = Image.ID[:]
id.sort() id.sort()
print "Supported formats (* indicates output format):" print("Supported formats (* indicates output format):")
for i in id: for i in id:
if i in Image.SAVE: if i in Image.SAVE:
print i+"*", print(i+"*", end=' ')
else: else:
print i, print(i, end=' ')
sys.exit(1) sys.exit(1)
elif o == "-c": elif o == "-c":
@ -92,5 +94,5 @@ try:
else: else:
apply(im.save, (argv[1],), options) apply(im.save, (argv[1],), options)
except: except:
print "cannot convert image", print("cannot convert image", end=' ')
print "(%s:%s)" % (sys.exc_info()[0], sys.exc_info()[1]) print("(%s:%s)" % (sys.exc_info()[0], sys.exc_info()[1]))

View File

@ -48,6 +48,8 @@ of its upper-left-hand corner and displays the cropped portion.
# 3. Add support for composing and decomposing multiple-image files. # 3. Add support for composing and decomposing multiple-image files.
# #
from __future__ import print_function
from PIL import Image from PIL import Image
class PILDriver: class PILDriver:
@ -481,7 +483,7 @@ class PILDriver:
self.push(list[0]) self.push(list[0])
list = list[1:] list = list[1:]
if self.verbose: if self.verbose:
print "Stack: " + `self.stack` print("Stack: " + `self.stack`)
top = self.top() top = self.top()
if type(top) != type(""): if type(top) != type(""):
continue; continue;
@ -507,15 +509,15 @@ if __name__ == '__main__':
if len(sys.argv[1:]) > 0: if len(sys.argv[1:]) > 0:
driver.execute(sys.argv[1:]) driver.execute(sys.argv[1:])
else: else:
print "PILDriver says hello." print("PILDriver says hello.")
while 1: while 1:
try: try:
line = raw_input('pildriver> '); line = raw_input('pildriver> ');
except EOFError: except EOFError:
print "\nPILDriver says goodbye." print("\nPILDriver says goodbye.")
break break
driver.execute(line.split()) driver.execute(line.split())
print driver.stack print(driver.stack)
# The following sets edit modes for GNU EMACS # The following sets edit modes for GNU EMACS
# Local Variables: # Local Variables:

View File

@ -17,25 +17,27 @@
# 0.4 2003-09-30 fl Expand wildcards on Windows; robustness tweaks # 0.4 2003-09-30 fl Expand wildcards on Windows; robustness tweaks
# #
from __future__ import print_function
import site import site
import getopt, glob, sys import getopt, glob, sys
from PIL import Image from PIL import Image
if len(sys.argv) == 1: if len(sys.argv) == 1:
print "PIL File 0.4/2003-09-30 -- identify image files" print("PIL File 0.4/2003-09-30 -- identify image files")
print "Usage: pilfile [option] files..." print("Usage: pilfile [option] files...")
print "Options:" print("Options:")
print " -f list supported file formats" print(" -f list supported file formats")
print " -i show associated info and tile data" print(" -i show associated info and tile data")
print " -v verify file headers" print(" -v verify file headers")
print " -q quiet, don't warn for unidentified/missing/broken files" print(" -q quiet, don't warn for unidentified/missing/broken files")
sys.exit(1) sys.exit(1)
try: try:
opt, args = getopt.getopt(sys.argv[1:], "fqivD") opt, args = getopt.getopt(sys.argv[1:], "fqivD")
except getopt.error as v: except getopt.error as v:
print v print(v)
sys.exit(1) sys.exit(1)
verbose = quiet = verify = 0 verbose = quiet = verify = 0
@ -45,9 +47,9 @@ for o, a in opt:
Image.init() Image.init()
id = Image.ID[:] id = Image.ID[:]
id.sort() id.sort()
print "Supported formats:" print("Supported formats:")
for i in id: for i in id:
print i, print(i, end=' ')
sys.exit(1) sys.exit(1)
elif o == "-i": elif o == "-i":
verbose = 1 verbose = 1
@ -73,22 +75,22 @@ def globfix(files):
for file in globfix(args): for file in globfix(args):
try: try:
im = Image.open(file) im = Image.open(file)
print "%s:" % file, im.format, "%dx%d" % im.size, im.mode, print("%s:" % file, im.format, "%dx%d" % im.size, im.mode, end=' ')
if verbose: if verbose:
print im.info, im.tile, print(im.info, im.tile, end=' ')
print print()
if verify: if verify:
try: try:
im.verify() im.verify()
except: except:
if not quiet: if not quiet:
print "failed to verify image", print("failed to verify image", end=' ')
print "(%s:%s)" % (sys.exc_info()[0], sys.exc_info()[1]) print("(%s:%s)" % (sys.exc_info()[0], sys.exc_info()[1]))
except IOError as v: except IOError as v:
if not quiet: if not quiet:
print file, "failed:", v print(file, "failed:", v)
except: except:
import traceback import traceback
if not quiet: if not quiet:
print file, "failed:", "unexpected error" print(file, "failed:", "unexpected error")
traceback.print_exc(file=sys.stdout) traceback.print_exc(file=sys.stdout)

View File

@ -9,6 +9,8 @@
# 2002-03-10 fl use "from PIL import" # 2002-03-10 fl use "from PIL import"
# #
from __future__ import print_function
VERSION = "0.4" VERSION = "0.4"
import site import site
@ -19,12 +21,12 @@ from PIL import BdfFontFile
from PIL import PcfFontFile from PIL import PcfFontFile
if len(sys.argv) <= 1: if len(sys.argv) <= 1:
print "PILFONT", VERSION, "-- PIL font compiler." print("PILFONT", VERSION, "-- PIL font compiler.")
print print()
print "Usage: pilfont fontfiles..." print("Usage: pilfont fontfiles...")
print print()
print "Convert given font files to the PIL raster font format." print("Convert given font files to the PIL raster font format.")
print "This version of pilfont supports X BDF and PCF fonts." print("This version of pilfont supports X BDF and PCF fonts.")
sys.exit(1) sys.exit(1)
files = [] files = []
@ -33,7 +35,7 @@ for f in sys.argv[1:]:
for f in files: for f in files:
print f + "...", print(f + "...", end=' ')
try: try:
@ -48,7 +50,7 @@ for f in files:
p.save(f) p.save(f)
except (SyntaxError, IOError): except (SyntaxError, IOError):
print "failed" print("failed")
else: else:
print "OK" print("OK")

View File

@ -11,6 +11,8 @@
# 0.3 2003-05-06 fl Fixed a typo or two. # 0.3 2003-05-06 fl Fixed a typo or two.
# #
from __future__ import print_function
VERSION = "pilprint 0.3/2003-05-05" VERSION = "pilprint 0.3/2003-05-05"
from PIL import Image from PIL import Image
@ -29,18 +31,18 @@ def description(file, image):
import getopt, os, sys import getopt, os, sys
if len(sys.argv) == 1: if len(sys.argv) == 1:
print "PIL Print 0.2a1/96-10-04 -- print image files" print("PIL Print 0.2a1/96-10-04 -- print image files")
print "Usage: pilprint files..." print("Usage: pilprint files...")
print "Options:" print("Options:")
print " -c colour printer (default is monochrome)" print(" -c colour printer (default is monochrome)")
print " -p print via lpr (default is stdout)" print(" -p print via lpr (default is stdout)")
print " -P <printer> same as -p but use given printer" print(" -P <printer> same as -p but use given printer")
sys.exit(1) sys.exit(1)
try: try:
opt, argv = getopt.getopt(sys.argv[1:], "cdpP:") opt, argv = getopt.getopt(sys.argv[1:], "cdpP:")
except getopt.error as v: except getopt.error as v:
print v print(v)
sys.exit(1) sys.exit(1)
printer = None # print to stdout printer = None # print to stdout
@ -50,7 +52,7 @@ for o, a in opt:
if o == "-d": if o == "-d":
# debug: show available drivers # debug: show available drivers
Image.init() Image.init()
print Image.ID print(Image.ID)
sys.exit(1) sys.exit(1)
elif o == "-c": elif o == "-c":
# colour printer # colour printer
@ -89,5 +91,5 @@ for file in argv:
ps.end_document() ps.end_document()
except: except:
print "cannot print image", print("cannot print image", end=' ')
print "(%s:%s)" % (sys.exc_info()[0], sys.exc_info()[1]) print("(%s:%s)" % (sys.exc_info()[0], sys.exc_info()[1]))

View File

@ -3,6 +3,8 @@
# $Id$ # $Id$
# #
from __future__ import print_function
from Tkinter import * from Tkinter import *
from PIL import Image, ImageTk from PIL import Image, ImageTk
import sys import sys
@ -98,7 +100,7 @@ class UI(Label):
if __name__ == "__main__": if __name__ == "__main__":
if not sys.argv[1:]: if not sys.argv[1:]:
print "Syntax: python player.py imagefile(s)" print("Syntax: python player.py imagefile(s)")
sys.exit(1) sys.exit(1)
filename = sys.argv[1] filename = sys.argv[1]
@ -108,7 +110,7 @@ if __name__ == "__main__":
if len(sys.argv) > 2: if len(sys.argv) > 2:
# list of images # list of images
print "loading..." print("loading...")
im = [] im = []
for filename in sys.argv[1:]: for filename in sys.argv[1:]:
im.append(Image.open(filename)) im.append(Image.open(filename))

View File

@ -3,6 +3,8 @@
# $Id$ # $Id$
# #
from __future__ import print_function
from Tkinter import * from Tkinter import *
from PIL import Image, ImageTk from PIL import Image, ImageTk
@ -31,7 +33,7 @@ if __name__ == "__main__":
import sys import sys
if not sys.argv[1:]: if not sys.argv[1:]:
print "Syntax: python viewer.py imagefile" print("Syntax: python viewer.py imagefile")
sys.exit(1) sys.exit(1)
filename = sys.argv[1] filename = sys.argv[1]