mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-27 17:54:32 +03:00
Merge pull request #2901 from wiredfool/remove-scripts
Removed scripts directory
This commit is contained in:
commit
cbc78d7e2a
|
@ -1,65 +0,0 @@
|
|||
Scripts
|
||||
=======
|
||||
|
||||
This directory contains a number of more or less trivial utilities
|
||||
and demo programs.
|
||||
|
||||
Comments and contributions are welcome.
|
||||
|
||||
</F>
|
||||
|
||||
pildriver.py (by Eric S. Raymond)
|
||||
--------------------------------------------------------------------
|
||||
|
||||
A class implementing an image-processing calculator for scripts.
|
||||
Parses lists of commands (or, called interactively, command-line
|
||||
arguments) into image loads, transformations, and saves.
|
||||
|
||||
viewer.py
|
||||
--------------------------------------------------------------------
|
||||
|
||||
A simple image viewer. Can display all file formats handled by
|
||||
PIL. Transparent images are properly handled.
|
||||
|
||||
thresholder.py
|
||||
--------------------------------------------------------------------
|
||||
|
||||
A simple utility that demonstrates how a transparent 1-bit overlay
|
||||
can be used to show the current thresholding of an 8-bit image.
|
||||
|
||||
enhancer.py
|
||||
--------------------------------------------------------------------
|
||||
|
||||
Illustrates the ImageEnhance module. Drag the sliders to modify the
|
||||
images. This might be very slow on some platforms, depending on the
|
||||
Tk version.
|
||||
|
||||
painter.py
|
||||
--------------------------------------------------------------------
|
||||
|
||||
Illustrates how a painting program could be based on PIL and Tk.
|
||||
Press the left mouse button and drag over the image to remove the
|
||||
colour. Some clever tricks have been used to get decent performance
|
||||
when updating the screen; see the sources for details.
|
||||
|
||||
player.py
|
||||
--------------------------------------------------------------------
|
||||
|
||||
A simple image sequence player. You can use either a sequence format
|
||||
like FLI/FLC, GIF, or ARG, or give a number of images which are
|
||||
interpreted as frames in a sequence. All frames must have the same
|
||||
size.
|
||||
|
||||
gifmaker.py
|
||||
--------------------------------------------------------------------
|
||||
|
||||
Convert a sequence file to a GIF animation.
|
||||
|
||||
Note that the GIF encoder provided with this release of PIL writes
|
||||
uncompressed GIF files only, so the resulting animations are rather
|
||||
large compared with these created by other tools.
|
||||
|
||||
explode.py
|
||||
--------------------------------------------------------------------
|
||||
|
||||
Split a sequence file into individual frames.
|
|
@ -1,64 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# The Python Imaging Library
|
||||
# $Id$
|
||||
#
|
||||
# this demo script creates four windows containing an image and a slider.
|
||||
# drag the slider to modify the image.
|
||||
#
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version_info[0] > 2:
|
||||
import tkinter
|
||||
else:
|
||||
import Tkinter as tkinter
|
||||
|
||||
from PIL import Image, ImageTk, ImageEnhance
|
||||
|
||||
#
|
||||
# enhancer widget
|
||||
|
||||
|
||||
class Enhance(tkinter.Frame):
|
||||
def __init__(self, master, image, name, enhancer, lo, hi):
|
||||
tkinter.Frame.__init__(self, master)
|
||||
|
||||
# set up the image
|
||||
self.tkim = ImageTk.PhotoImage(image.mode, image.size)
|
||||
self.enhancer = enhancer(image)
|
||||
self.update("1.0") # normalize
|
||||
|
||||
# image window
|
||||
tkinter.Label(self, image=self.tkim).pack()
|
||||
|
||||
# scale
|
||||
s = tkinter.Scale(self, label=name, orient=tkinter.HORIZONTAL,
|
||||
from_=lo, to=hi, resolution=0.01,
|
||||
command=self.update)
|
||||
s.set(self.value)
|
||||
s.pack()
|
||||
|
||||
def update(self, value):
|
||||
self.value = float(value)
|
||||
self.tkim.paste(self.enhancer.enhance(self.value))
|
||||
|
||||
#
|
||||
# main
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: enhancer file")
|
||||
sys.exit(1)
|
||||
|
||||
root = tkinter.Tk()
|
||||
|
||||
im = Image.open(sys.argv[1])
|
||||
|
||||
im.thumbnail((200, 200))
|
||||
|
||||
Enhance(root, im, "Color", ImageEnhance.Color, 0.0, 4.0).pack()
|
||||
Enhance(tkinter.Toplevel(), im, "Sharpness", ImageEnhance.Sharpness, -2.0, 2.0).pack()
|
||||
Enhance(tkinter.Toplevel(), im, "Brightness", ImageEnhance.Brightness, -1.0, 3.0).pack()
|
||||
Enhance(tkinter.Toplevel(), im, "Contrast", ImageEnhance.Contrast, -1.0, 3.0).pack()
|
||||
|
||||
root.mainloop()
|
|
@ -1,112 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# The Python Imaging Library
|
||||
# $Id$
|
||||
#
|
||||
# split an animation into a number of frame files
|
||||
#
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
from PIL import Image
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
class Interval(object):
|
||||
|
||||
def __init__(self, interval="0"):
|
||||
|
||||
self.setinterval(interval)
|
||||
|
||||
def setinterval(self, interval):
|
||||
|
||||
self.hilo = []
|
||||
|
||||
for s in interval.split(","):
|
||||
if not s.strip():
|
||||
continue
|
||||
try:
|
||||
v = int(s)
|
||||
if v < 0:
|
||||
lo, hi = 0, -v
|
||||
else:
|
||||
lo = hi = v
|
||||
except ValueError:
|
||||
i = s.find("-")
|
||||
lo, hi = int(s[:i]), int(s[i+1:])
|
||||
|
||||
self.hilo.append((hi, lo))
|
||||
|
||||
if not self.hilo:
|
||||
self.hilo = [(sys.maxsize, 0)]
|
||||
|
||||
def __getitem__(self, index):
|
||||
|
||||
for hi, lo in self.hilo:
|
||||
if hi >= index >= lo:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# main program
|
||||
|
||||
html = 0
|
||||
|
||||
if sys.argv[1:2] == ["-h"]:
|
||||
html = 1
|
||||
del sys.argv[1]
|
||||
|
||||
if not sys.argv[2:]:
|
||||
print()
|
||||
print("Syntax: python explode.py infile template [range]")
|
||||
print()
|
||||
print("The template argument is used to construct the names of the")
|
||||
print("individual frame files. The frames are numbered file001.ext,")
|
||||
print("file002.ext, etc. You can insert %d to control the placement")
|
||||
print("and syntax of the frame number.")
|
||||
print()
|
||||
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("omitted, all frames are extracted.")
|
||||
sys.exit(1)
|
||||
|
||||
infile = sys.argv[1]
|
||||
outfile = sys.argv[2]
|
||||
|
||||
frames = Interval(",".join(sys.argv[3:]))
|
||||
|
||||
try:
|
||||
# check if outfile contains a placeholder
|
||||
outfile % 1
|
||||
except TypeError:
|
||||
file, ext = os.path.splitext(outfile)
|
||||
outfile = file + "%03d" + ext
|
||||
|
||||
ix = 1
|
||||
|
||||
im = Image.open(infile)
|
||||
|
||||
if html:
|
||||
file, ext = os.path.splitext(outfile)
|
||||
html = open(file+".html", "w")
|
||||
html.write("<html>\n<body>\n")
|
||||
|
||||
while True:
|
||||
|
||||
if frames[ix]:
|
||||
im.save(outfile % ix)
|
||||
print(outfile % ix)
|
||||
|
||||
if html:
|
||||
html.write("<img src='%s'><br>\n" % outfile % ix)
|
||||
|
||||
try:
|
||||
im.seek(ix)
|
||||
except EOFError:
|
||||
break
|
||||
|
||||
ix += 1
|
||||
|
||||
if html:
|
||||
html.write("</body>\n</html>\n")
|
|
@ -1,31 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# The Python Imaging Library
|
||||
# $Id$
|
||||
#
|
||||
# convert sequence format to GIF animation
|
||||
#
|
||||
# history:
|
||||
# 97-01-03 fl created
|
||||
#
|
||||
# Copyright (c) Secret Labs AB 1997. All rights reserved.
|
||||
# Copyright (c) Fredrik Lundh 1997.
|
||||
#
|
||||
# See the README file for information on usage and redistribution.
|
||||
#
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
from PIL import Image
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
import sys
|
||||
|
||||
if len(sys.argv) < 3:
|
||||
print("GIFMAKER -- create GIF animations")
|
||||
print("Usage: gifmaker infile outfile")
|
||||
sys.exit(1)
|
||||
|
||||
im = Image.open(sys.argv[1])
|
||||
im.save(sys.argv[2], save_all=True)
|
|
@ -1,84 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# The Python Imaging Library
|
||||
# $Id$
|
||||
#
|
||||
# this demo script illustrates pasting into an already displayed
|
||||
# photoimage. note that the current version of Tk updates the whole
|
||||
# image every time we paste, so to get decent performance, we split
|
||||
# the image into a set of tiles.
|
||||
#
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version_info[0] > 2:
|
||||
import tkinter
|
||||
else:
|
||||
import Tkinter as tkinter
|
||||
|
||||
from PIL import Image, ImageTk
|
||||
|
||||
#
|
||||
# painter widget
|
||||
|
||||
|
||||
class PaintCanvas(tkinter.Canvas):
|
||||
def __init__(self, master, image):
|
||||
tkinter.Canvas.__init__(self, master,
|
||||
width=image.size[0], height=image.size[1])
|
||||
|
||||
# fill the canvas
|
||||
self.tile = {}
|
||||
self.tilesize = tilesize = 32
|
||||
xsize, ysize = image.size
|
||||
for x in range(0, xsize, tilesize):
|
||||
for y in range(0, ysize, tilesize):
|
||||
box = x, y, min(xsize, x+tilesize), min(ysize, y+tilesize)
|
||||
tile = ImageTk.PhotoImage(image.crop(box))
|
||||
self.create_image(x, y, image=tile, anchor=tkinter.NW)
|
||||
self.tile[(x, y)] = box, tile
|
||||
|
||||
self.image = image
|
||||
|
||||
self.bind("<B1-Motion>", self.paint)
|
||||
|
||||
def paint(self, event):
|
||||
xy = event.x - 10, event.y - 10, event.x + 10, event.y + 10
|
||||
im = self.image.crop(xy)
|
||||
|
||||
# process the image in some fashion
|
||||
im = im.convert("L")
|
||||
|
||||
self.image.paste(im, xy)
|
||||
self.repair(xy)
|
||||
|
||||
def repair(self, box):
|
||||
# update canvas
|
||||
dx = box[0] % self.tilesize
|
||||
dy = box[1] % self.tilesize
|
||||
for x in range(box[0]-dx, box[2]+1, self.tilesize):
|
||||
for y in range(box[1]-dy, box[3]+1, self.tilesize):
|
||||
try:
|
||||
xy, tile = self.tile[(x, y)]
|
||||
tile.paste(self.image.crop(xy))
|
||||
except KeyError:
|
||||
pass # outside the image
|
||||
self.update_idletasks()
|
||||
|
||||
#
|
||||
# main
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: painter file")
|
||||
sys.exit(1)
|
||||
|
||||
root = tkinter.Tk()
|
||||
|
||||
im = Image.open(sys.argv[1])
|
||||
|
||||
if im.mode != "RGB":
|
||||
im = im.convert("RGB")
|
||||
|
||||
PaintCanvas(root, im).pack()
|
||||
|
||||
root.mainloop()
|
|
@ -1,99 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# The Python Imaging Library.
|
||||
# $Id$
|
||||
#
|
||||
# convert image files
|
||||
#
|
||||
# History:
|
||||
# 0.1 96-04-20 fl Created
|
||||
# 0.2 96-10-04 fl Use draft mode when converting images
|
||||
# 0.3 96-12-30 fl Optimize output (PNG, JPEG)
|
||||
# 0.4 97-01-18 fl Made optimize an option (PNG, JPEG)
|
||||
# 0.5 98-12-30 fl Fixed -f option (from Anthony Baxter)
|
||||
#
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import getopt
|
||||
import string
|
||||
import sys
|
||||
|
||||
from PIL import Image
|
||||
|
||||
|
||||
def usage():
|
||||
print("PIL Convert 0.5/1998-12-30 -- convert image files")
|
||||
print("Usage: pilconvert [option] infile outfile")
|
||||
print()
|
||||
print("Options:")
|
||||
print()
|
||||
print(" -c <format> convert to format (default is given by extension)")
|
||||
print()
|
||||
print(" -g convert to greyscale")
|
||||
print(" -p convert to palette image (using standard palette)")
|
||||
print(" -r convert to rgb")
|
||||
print()
|
||||
print(" -o optimize output (trade speed for size)")
|
||||
print(" -q <value> set compression quality (0-100, JPEG only)")
|
||||
print()
|
||||
print(" -f list supported file formats")
|
||||
sys.exit(1)
|
||||
|
||||
if len(sys.argv) == 1:
|
||||
usage()
|
||||
|
||||
try:
|
||||
opt, argv = getopt.getopt(sys.argv[1:], "c:dfgopq:r")
|
||||
except getopt.error as v:
|
||||
print(v)
|
||||
sys.exit(1)
|
||||
|
||||
output_format = None
|
||||
convert = None
|
||||
|
||||
options = {}
|
||||
|
||||
for o, a in opt:
|
||||
|
||||
if o == "-f":
|
||||
Image.init()
|
||||
id = sorted(Image.ID)
|
||||
print("Supported formats (* indicates output format):")
|
||||
for i in id:
|
||||
if i in Image.SAVE:
|
||||
print(i+"*", end=' ')
|
||||
else:
|
||||
print(i, end=' ')
|
||||
sys.exit(1)
|
||||
|
||||
elif o == "-c":
|
||||
output_format = a
|
||||
|
||||
if o == "-g":
|
||||
convert = "L"
|
||||
elif o == "-p":
|
||||
convert = "P"
|
||||
elif o == "-r":
|
||||
convert = "RGB"
|
||||
|
||||
elif o == "-o":
|
||||
options["optimize"] = 1
|
||||
elif o == "-q":
|
||||
options["quality"] = string.atoi(a)
|
||||
|
||||
if len(argv) != 2:
|
||||
usage()
|
||||
|
||||
try:
|
||||
im = Image.open(argv[0])
|
||||
if convert and im.mode != convert:
|
||||
im.draft(convert, im.size)
|
||||
im = im.convert(convert)
|
||||
if output_format:
|
||||
im.save(argv[1], output_format, **options)
|
||||
else:
|
||||
im.save(argv[1], **options)
|
||||
except:
|
||||
print("cannot convert image", end=' ')
|
||||
print("(%s:%s)" % (sys.exc_info()[0], sys.exc_info()[1]))
|
|
@ -1,526 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
"""PILdriver, an image-processing calculator using PIL.
|
||||
|
||||
An instance of class PILDriver is essentially a software stack machine
|
||||
(Polish-notation interpreter) for sequencing PIL image
|
||||
transformations. The state of the instance is the interpreter stack.
|
||||
|
||||
The only method one will normally invoke after initialization is the
|
||||
`execute' method. This takes an argument list of tokens, pushes them
|
||||
onto the instance's stack, and then tries to clear the stack by
|
||||
successive evaluation of PILdriver operators. Any part of the stack
|
||||
not cleaned off persists and is part of the evaluation context for
|
||||
the next call of the execute method.
|
||||
|
||||
PILDriver doesn't catch any exceptions, on the theory that these
|
||||
are actually diagnostic information that should be interpreted by
|
||||
the calling code.
|
||||
|
||||
When called as a script, the command-line arguments are passed to
|
||||
a PILDriver instance. If there are no command-line arguments, the
|
||||
module runs an interactive interpreter, each line of which is split into
|
||||
space-separated tokens and passed to the execute method.
|
||||
|
||||
In the method descriptions below, a first line beginning with the string
|
||||
`usage:' means this method can be invoked with the token that follows
|
||||
it. Following <>-enclosed arguments describe how the method interprets
|
||||
the entries on the stack. Each argument specification begins with a
|
||||
type specification: either `int', `float', `string', or `image'.
|
||||
|
||||
All operations consume their arguments off the stack (use `dup' to
|
||||
keep copies around). Use `verbose 1' to see the stack state displayed
|
||||
before each operation.
|
||||
|
||||
Usage examples:
|
||||
|
||||
`show crop 0 0 200 300 open test.png' loads test.png, crops out a portion
|
||||
of its upper-left-hand corner and displays the cropped portion.
|
||||
|
||||
`save rotated.png rotate 30 open test.tiff' loads test.tiff, rotates it
|
||||
30 degrees, and saves the result as rotated.png (in PNG format).
|
||||
"""
|
||||
# by Eric S. Raymond <esr@thyrsus.com>
|
||||
# $Id$
|
||||
|
||||
# TO DO:
|
||||
# 1. Add PILFont capabilities, once that's documented.
|
||||
# 2. Add PILDraw operations.
|
||||
# 3. Add support for composing and decomposing multiple-image files.
|
||||
#
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
from PIL import Image
|
||||
|
||||
|
||||
class PILDriver(object):
|
||||
|
||||
verbose = 0
|
||||
|
||||
def do_verbose(self):
|
||||
"""usage: verbose <int:num>
|
||||
|
||||
Set verbosity flag from top of stack.
|
||||
"""
|
||||
self.verbose = int(self.do_pop())
|
||||
|
||||
# The evaluation stack (internal only)
|
||||
|
||||
stack = [] # Stack of pending operations
|
||||
|
||||
def push(self, item):
|
||||
"Push an argument onto the evaluation stack."
|
||||
self.stack.insert(0, item)
|
||||
|
||||
def top(self):
|
||||
"Return the top-of-stack element."
|
||||
return self.stack[0]
|
||||
|
||||
# Stack manipulation (callable)
|
||||
|
||||
def do_clear(self):
|
||||
"""usage: clear
|
||||
|
||||
Clear the stack.
|
||||
"""
|
||||
self.stack = []
|
||||
|
||||
def do_pop(self):
|
||||
"""usage: pop
|
||||
|
||||
Discard the top element on the stack.
|
||||
"""
|
||||
return self.stack.pop(0)
|
||||
|
||||
def do_dup(self):
|
||||
"""usage: dup
|
||||
|
||||
Duplicate the top-of-stack item.
|
||||
"""
|
||||
if hasattr(self, 'format'): # If it's an image, do a real copy
|
||||
dup = self.stack[0].copy()
|
||||
else:
|
||||
dup = self.stack[0]
|
||||
self.push(dup)
|
||||
|
||||
def do_swap(self):
|
||||
"""usage: swap
|
||||
|
||||
Swap the top-of-stack item with the next one down.
|
||||
"""
|
||||
self.stack = [self.stack[1], self.stack[0]] + self.stack[2:]
|
||||
|
||||
# Image module functions (callable)
|
||||
|
||||
def do_new(self):
|
||||
"""usage: new <int:xsize> <int:ysize> <int:color>:
|
||||
|
||||
Create and push a greyscale image of given size and color.
|
||||
"""
|
||||
xsize = int(self.do_pop())
|
||||
ysize = int(self.do_pop())
|
||||
color = int(self.do_pop())
|
||||
self.push(Image.new("L", (xsize, ysize), color))
|
||||
|
||||
def do_open(self):
|
||||
"""usage: open <string:filename>
|
||||
|
||||
Open the indicated image, read it, push the image on the stack.
|
||||
"""
|
||||
self.push(Image.open(self.do_pop()))
|
||||
|
||||
def do_blend(self):
|
||||
"""usage: blend <image:pic1> <image:pic2> <float:alpha>
|
||||
|
||||
Replace two images and an alpha with the blended image.
|
||||
"""
|
||||
image1 = self.do_pop()
|
||||
image2 = self.do_pop()
|
||||
alpha = float(self.do_pop())
|
||||
self.push(Image.blend(image1, image2, alpha))
|
||||
|
||||
def do_composite(self):
|
||||
"""usage: composite <image:pic1> <image:pic2> <image:mask>
|
||||
|
||||
Replace two images and a mask with their composite.
|
||||
"""
|
||||
image1 = self.do_pop()
|
||||
image2 = self.do_pop()
|
||||
mask = self.do_pop()
|
||||
self.push(Image.composite(image1, image2, mask))
|
||||
|
||||
def do_merge(self):
|
||||
"""usage: merge <string:mode> <image:pic1>
|
||||
[<image:pic2> [<image:pic3> [<image:pic4>]]]
|
||||
|
||||
Merge top-of stack images in a way described by the mode.
|
||||
"""
|
||||
mode = self.do_pop()
|
||||
bandlist = []
|
||||
for band in mode:
|
||||
bandlist.append(self.do_pop())
|
||||
self.push(Image.merge(mode, bandlist))
|
||||
|
||||
# Image class methods
|
||||
|
||||
def do_convert(self):
|
||||
"""usage: convert <string:mode> <image:pic1>
|
||||
|
||||
Convert the top image to the given mode.
|
||||
"""
|
||||
mode = self.do_pop()
|
||||
image = self.do_pop()
|
||||
self.push(image.convert(mode))
|
||||
|
||||
def do_copy(self):
|
||||
"""usage: copy <image:pic1>
|
||||
|
||||
Make and push a true copy of the top image.
|
||||
"""
|
||||
self.dup()
|
||||
|
||||
def do_crop(self):
|
||||
"""usage: crop <int:left> <int:upper> <int:right> <int:lower>
|
||||
<image:pic1>
|
||||
|
||||
Crop and push a rectangular region from the current image.
|
||||
"""
|
||||
left = int(self.do_pop())
|
||||
upper = int(self.do_pop())
|
||||
right = int(self.do_pop())
|
||||
lower = int(self.do_pop())
|
||||
image = self.do_pop()
|
||||
self.push(image.crop((left, upper, right, lower)))
|
||||
|
||||
def do_draft(self):
|
||||
"""usage: draft <string:mode> <int:xsize> <int:ysize>
|
||||
|
||||
Configure the loader for a given mode and size.
|
||||
"""
|
||||
mode = self.do_pop()
|
||||
xsize = int(self.do_pop())
|
||||
ysize = int(self.do_pop())
|
||||
self.push(self.draft(mode, (xsize, ysize)))
|
||||
|
||||
def do_filter(self):
|
||||
"""usage: filter <string:filtername> <image:pic1>
|
||||
|
||||
Process the top image with the given filter.
|
||||
"""
|
||||
from PIL import ImageFilter
|
||||
imageFilter = getattr(ImageFilter, self.do_pop().upper())
|
||||
image = self.do_pop()
|
||||
self.push(image.filter(imageFilter))
|
||||
|
||||
def do_getbbox(self):
|
||||
"""usage: getbbox
|
||||
|
||||
Push left, upper, right, and lower pixel coordinates of the top image.
|
||||
"""
|
||||
bounding_box = self.do_pop().getbbox()
|
||||
self.push(bounding_box[3])
|
||||
self.push(bounding_box[2])
|
||||
self.push(bounding_box[1])
|
||||
self.push(bounding_box[0])
|
||||
|
||||
def do_getextrema(self):
|
||||
"""usage: extrema
|
||||
|
||||
Push minimum and maximum pixel values of the top image.
|
||||
"""
|
||||
extrema = self.do_pop().extrema()
|
||||
self.push(extrema[1])
|
||||
self.push(extrema[0])
|
||||
|
||||
def do_offset(self):
|
||||
"""usage: offset <int:xoffset> <int:yoffset> <image:pic1>
|
||||
|
||||
Offset the pixels in the top image.
|
||||
"""
|
||||
xoff = int(self.do_pop())
|
||||
yoff = int(self.do_pop())
|
||||
image = self.do_pop()
|
||||
self.push(image.offset(xoff, yoff))
|
||||
|
||||
def do_paste(self):
|
||||
"""usage: paste <image:figure> <int:xoffset> <int:yoffset>
|
||||
<image:ground>
|
||||
|
||||
Paste figure image into ground with upper left at given offsets.
|
||||
"""
|
||||
figure = self.do_pop()
|
||||
xoff = int(self.do_pop())
|
||||
yoff = int(self.do_pop())
|
||||
ground = self.do_pop()
|
||||
if figure.mode == "RGBA":
|
||||
ground.paste(figure, (xoff, yoff), figure)
|
||||
else:
|
||||
ground.paste(figure, (xoff, yoff))
|
||||
self.push(ground)
|
||||
|
||||
def do_resize(self):
|
||||
"""usage: resize <int:xsize> <int:ysize> <image:pic1>
|
||||
|
||||
Resize the top image.
|
||||
"""
|
||||
ysize = int(self.do_pop())
|
||||
xsize = int(self.do_pop())
|
||||
image = self.do_pop()
|
||||
self.push(image.resize((xsize, ysize)))
|
||||
|
||||
def do_rotate(self):
|
||||
"""usage: rotate <int:angle> <image:pic1>
|
||||
|
||||
Rotate image through a given angle
|
||||
"""
|
||||
angle = int(self.do_pop())
|
||||
image = self.do_pop()
|
||||
self.push(image.rotate(angle))
|
||||
|
||||
def do_save(self):
|
||||
"""usage: save <string:filename> <image:pic1>
|
||||
|
||||
Save image with default options.
|
||||
"""
|
||||
filename = self.do_pop()
|
||||
image = self.do_pop()
|
||||
image.save(filename)
|
||||
|
||||
def do_save2(self):
|
||||
"""usage: save2 <string:filename> <string:options> <image:pic1>
|
||||
|
||||
Save image with specified options.
|
||||
"""
|
||||
filename = self.do_pop()
|
||||
options = self.do_pop()
|
||||
image = self.do_pop()
|
||||
image.save(filename, None, options)
|
||||
|
||||
def do_show(self):
|
||||
"""usage: show <image:pic1>
|
||||
|
||||
Display and pop the top image.
|
||||
"""
|
||||
self.do_pop().show()
|
||||
|
||||
def do_thumbnail(self):
|
||||
"""usage: thumbnail <int:xsize> <int:ysize> <image:pic1>
|
||||
|
||||
Modify the top image in the stack to contain a thumbnail of itself.
|
||||
"""
|
||||
ysize = int(self.do_pop())
|
||||
xsize = int(self.do_pop())
|
||||
self.top().thumbnail((xsize, ysize))
|
||||
|
||||
def do_transpose(self):
|
||||
"""usage: transpose <string:operator> <image:pic1>
|
||||
|
||||
Transpose the top image.
|
||||
"""
|
||||
transpose = self.do_pop().upper()
|
||||
image = self.do_pop()
|
||||
self.push(image.transpose(transpose))
|
||||
|
||||
# Image attributes
|
||||
|
||||
def do_format(self):
|
||||
"""usage: format <image:pic1>
|
||||
|
||||
Push the format of the top image onto the stack.
|
||||
"""
|
||||
self.push(self.do_pop().format)
|
||||
|
||||
def do_mode(self):
|
||||
"""usage: mode <image:pic1>
|
||||
|
||||
Push the mode of the top image onto the stack.
|
||||
"""
|
||||
self.push(self.do_pop().mode)
|
||||
|
||||
def do_size(self):
|
||||
"""usage: size <image:pic1>
|
||||
|
||||
Push the image size on the stack as (y, x).
|
||||
"""
|
||||
size = self.do_pop().size
|
||||
self.push(size[0])
|
||||
self.push(size[1])
|
||||
|
||||
# ImageChops operations
|
||||
|
||||
def do_invert(self):
|
||||
"""usage: invert <image:pic1>
|
||||
|
||||
Invert the top image.
|
||||
"""
|
||||
from PIL import ImageChops
|
||||
self.push(ImageChops.invert(self.do_pop()))
|
||||
|
||||
def do_lighter(self):
|
||||
"""usage: lighter <image:pic1> <image:pic2>
|
||||
|
||||
Pop the two top images, push an image of the lighter pixels of both.
|
||||
"""
|
||||
from PIL import ImageChops
|
||||
image1 = self.do_pop()
|
||||
image2 = self.do_pop()
|
||||
self.push(ImageChops.lighter(image1, image2))
|
||||
|
||||
def do_darker(self):
|
||||
"""usage: darker <image:pic1> <image:pic2>
|
||||
|
||||
Pop the two top images, push an image of the darker pixels of both.
|
||||
"""
|
||||
from PIL import ImageChops
|
||||
image1 = self.do_pop()
|
||||
image2 = self.do_pop()
|
||||
self.push(ImageChops.darker(image1, image2))
|
||||
|
||||
def do_difference(self):
|
||||
"""usage: difference <image:pic1> <image:pic2>
|
||||
|
||||
Pop the two top images, push the difference image
|
||||
"""
|
||||
from PIL import ImageChops
|
||||
image1 = self.do_pop()
|
||||
image2 = self.do_pop()
|
||||
self.push(ImageChops.difference(image1, image2))
|
||||
|
||||
def do_multiply(self):
|
||||
"""usage: multiply <image:pic1> <image:pic2>
|
||||
|
||||
Pop the two top images, push the multiplication image.
|
||||
"""
|
||||
from PIL import ImageChops
|
||||
image1 = self.do_pop()
|
||||
image2 = self.do_pop()
|
||||
self.push(ImageChops.multiply(image1, image2))
|
||||
|
||||
def do_screen(self):
|
||||
"""usage: screen <image:pic1> <image:pic2>
|
||||
|
||||
Pop the two top images, superimpose their inverted versions.
|
||||
"""
|
||||
from PIL import ImageChops
|
||||
image2 = self.do_pop()
|
||||
image1 = self.do_pop()
|
||||
self.push(ImageChops.screen(image1, image2))
|
||||
|
||||
def do_add(self):
|
||||
"""usage: add <image:pic1> <image:pic2> <int:offset> <float:scale>
|
||||
|
||||
Pop the two top images, produce the scaled sum with offset.
|
||||
"""
|
||||
from PIL import ImageChops
|
||||
image1 = self.do_pop()
|
||||
image2 = self.do_pop()
|
||||
scale = float(self.do_pop())
|
||||
offset = int(self.do_pop())
|
||||
self.push(ImageChops.add(image1, image2, scale, offset))
|
||||
|
||||
def do_subtract(self):
|
||||
"""usage: subtract <image:pic1> <image:pic2> <int:offset> <float:scale>
|
||||
|
||||
Pop the two top images, produce the scaled difference with offset.
|
||||
"""
|
||||
from PIL import ImageChops
|
||||
image1 = self.do_pop()
|
||||
image2 = self.do_pop()
|
||||
scale = float(self.do_pop())
|
||||
offset = int(self.do_pop())
|
||||
self.push(ImageChops.subtract(image1, image2, scale, offset))
|
||||
|
||||
# ImageEnhance classes
|
||||
|
||||
def do_color(self):
|
||||
"""usage: color <image:pic1>
|
||||
|
||||
Enhance color in the top image.
|
||||
"""
|
||||
from PIL import ImageEnhance
|
||||
factor = float(self.do_pop())
|
||||
image = self.do_pop()
|
||||
enhancer = ImageEnhance.Color(image)
|
||||
self.push(enhancer.enhance(factor))
|
||||
|
||||
def do_contrast(self):
|
||||
"""usage: contrast <image:pic1>
|
||||
|
||||
Enhance contrast in the top image.
|
||||
"""
|
||||
from PIL import ImageEnhance
|
||||
factor = float(self.do_pop())
|
||||
image = self.do_pop()
|
||||
enhancer = ImageEnhance.Contrast(image)
|
||||
self.push(enhancer.enhance(factor))
|
||||
|
||||
def do_brightness(self):
|
||||
"""usage: brightness <image:pic1>
|
||||
|
||||
Enhance brightness in the top image.
|
||||
"""
|
||||
from PIL import ImageEnhance
|
||||
factor = float(self.do_pop())
|
||||
image = self.do_pop()
|
||||
enhancer = ImageEnhance.Brightness(image)
|
||||
self.push(enhancer.enhance(factor))
|
||||
|
||||
def do_sharpness(self):
|
||||
"""usage: sharpness <image:pic1>
|
||||
|
||||
Enhance sharpness in the top image.
|
||||
"""
|
||||
from PIL import ImageEnhance
|
||||
factor = float(self.do_pop())
|
||||
image = self.do_pop()
|
||||
enhancer = ImageEnhance.Sharpness(image)
|
||||
self.push(enhancer.enhance(factor))
|
||||
|
||||
# The interpreter loop
|
||||
|
||||
def execute(self, list):
|
||||
"Interpret a list of PILDriver commands."
|
||||
list.reverse()
|
||||
while len(list) > 0:
|
||||
self.push(list[0])
|
||||
list = list[1:]
|
||||
if self.verbose:
|
||||
print("Stack: " + repr(self.stack))
|
||||
top = self.top()
|
||||
if not isinstance(top, str):
|
||||
continue
|
||||
funcname = "do_" + top
|
||||
if not hasattr(self, funcname):
|
||||
continue
|
||||
else:
|
||||
self.do_pop()
|
||||
func = getattr(self, funcname)
|
||||
func()
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
|
||||
# If we see command-line arguments, interpret them as a stack state
|
||||
# and execute. Otherwise go interactive.
|
||||
|
||||
driver = PILDriver()
|
||||
if len(sys.argv[1:]) > 0:
|
||||
driver.execute(sys.argv[1:])
|
||||
else:
|
||||
print("PILDriver says hello.")
|
||||
while True:
|
||||
try:
|
||||
if sys.version_info[0] >= 3:
|
||||
line = input('pildriver> ')
|
||||
else:
|
||||
line = raw_input('pildriver> ')
|
||||
except EOFError:
|
||||
print("\nPILDriver says goodbye.")
|
||||
break
|
||||
driver.execute(line.split())
|
||||
print(driver.stack)
|
||||
|
||||
# The following sets edit modes for GNU EMACS
|
||||
# Local Variables:
|
||||
# mode:python
|
||||
# End:
|
|
@ -1,101 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# The Python Imaging Library.
|
||||
# $Id$
|
||||
#
|
||||
# a utility to identify image files
|
||||
#
|
||||
# this script identifies image files, extracting size and
|
||||
# pixel mode information for known file formats. Note that
|
||||
# you don't need the PIL C extension to use this module.
|
||||
#
|
||||
# History:
|
||||
# 0.0 1995-09-01 fl Created
|
||||
# 0.1 1996-05-18 fl Modified options, added debugging mode
|
||||
# 0.2 1996-12-29 fl Added verify mode
|
||||
# 0.3 1999-06-05 fl Don't mess up on class exceptions (1.5.2 and later)
|
||||
# 0.4 2003-09-30 fl Expand wildcards on Windows; robustness tweaks
|
||||
#
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import getopt
|
||||
import glob
|
||||
import logging
|
||||
import sys
|
||||
|
||||
from PIL import Image
|
||||
|
||||
if len(sys.argv) == 1:
|
||||
print("PIL File 0.4/2003-09-30 -- identify image files")
|
||||
print("Usage: pilfile [option] files...")
|
||||
print("Options:")
|
||||
print(" -f list supported file formats")
|
||||
print(" -i show associated info and tile data")
|
||||
print(" -v verify file headers")
|
||||
print(" -q quiet, don't warn for unidentified/missing/broken files")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
opt, args = getopt.getopt(sys.argv[1:], "fqivD")
|
||||
except getopt.error as v:
|
||||
print(v)
|
||||
sys.exit(1)
|
||||
|
||||
verbose = quiet = verify = 0
|
||||
logging_level = "WARNING"
|
||||
|
||||
for o, a in opt:
|
||||
if o == "-f":
|
||||
Image.init()
|
||||
id = sorted(Image.ID)
|
||||
print("Supported formats:")
|
||||
for i in id:
|
||||
print(i, end=' ')
|
||||
sys.exit(1)
|
||||
elif o == "-i":
|
||||
verbose = 1
|
||||
elif o == "-q":
|
||||
quiet = 1
|
||||
elif o == "-v":
|
||||
verify = 1
|
||||
elif o == "-D":
|
||||
logging_level = "DEBUG"
|
||||
|
||||
logging.basicConfig(level=logging_level)
|
||||
|
||||
|
||||
def globfix(files):
|
||||
# expand wildcards where necessary
|
||||
if sys.platform == "win32":
|
||||
out = []
|
||||
for file in files:
|
||||
if glob.has_magic(file):
|
||||
out.extend(glob.glob(file))
|
||||
else:
|
||||
out.append(file)
|
||||
return out
|
||||
return files
|
||||
|
||||
for file in globfix(args):
|
||||
try:
|
||||
im = Image.open(file)
|
||||
print("%s:" % file, im.format, "%dx%d" % im.size, im.mode, end=' ')
|
||||
if verbose:
|
||||
print(im.info, im.tile, end=' ')
|
||||
print()
|
||||
if verify:
|
||||
try:
|
||||
im.verify()
|
||||
except:
|
||||
if not quiet:
|
||||
print("failed to verify image", end=' ')
|
||||
print("(%s:%s)" % (sys.exc_info()[0], sys.exc_info()[1]))
|
||||
except IOError as v:
|
||||
if not quiet:
|
||||
print(file, "failed:", v)
|
||||
except:
|
||||
import traceback
|
||||
if not quiet:
|
||||
print(file, "failed:", "unexpected error")
|
||||
traceback.print_exc(file=sys.stdout)
|
|
@ -1,57 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# The Python Imaging Library
|
||||
# $Id$
|
||||
#
|
||||
# PIL raster font compiler
|
||||
#
|
||||
# history:
|
||||
# 1997-08-25 fl created
|
||||
# 2002-03-10 fl use "from PIL import"
|
||||
#
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import glob
|
||||
import sys
|
||||
|
||||
# drivers
|
||||
from PIL import BdfFontFile
|
||||
from PIL import PcfFontFile
|
||||
|
||||
VERSION = "0.4"
|
||||
|
||||
if len(sys.argv) <= 1:
|
||||
print("PILFONT", VERSION, "-- PIL font compiler.")
|
||||
print()
|
||||
print("Usage: pilfont fontfiles...")
|
||||
print()
|
||||
print("Convert given font files to the PIL raster font format.")
|
||||
print("This version of pilfont supports X BDF and PCF fonts.")
|
||||
sys.exit(1)
|
||||
|
||||
files = []
|
||||
for f in sys.argv[1:]:
|
||||
files = files + glob.glob(f)
|
||||
|
||||
for f in files:
|
||||
|
||||
print(f + "...", end=' ')
|
||||
|
||||
try:
|
||||
|
||||
fp = open(f, "rb")
|
||||
|
||||
try:
|
||||
p = PcfFontFile.PcfFontFile(fp)
|
||||
except SyntaxError:
|
||||
fp.seek(0)
|
||||
p = BdfFontFile.BdfFontFile(fp)
|
||||
|
||||
p.save(f)
|
||||
|
||||
except (SyntaxError, IOError):
|
||||
print("failed")
|
||||
|
||||
else:
|
||||
print("OK")
|
|
@ -1,102 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# The Python Imaging Library.
|
||||
# $Id$
|
||||
#
|
||||
# print image files to postscript printer
|
||||
#
|
||||
# History:
|
||||
# 0.1 1996-04-20 fl Created
|
||||
# 0.2 1996-10-04 fl Use draft mode when converting.
|
||||
# 0.3 2003-05-06 fl Fixed a typo or two.
|
||||
#
|
||||
|
||||
from __future__ import print_function
|
||||
import getopt
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
VERSION = "pilprint 0.3/2003-05-05"
|
||||
|
||||
from PIL import Image
|
||||
from PIL import PSDraw
|
||||
|
||||
letter = (1.0*72, 1.0*72, 7.5*72, 10.0*72)
|
||||
|
||||
|
||||
def description(filepath, image):
|
||||
title = os.path.splitext(os.path.split(filepath)[1])[0]
|
||||
format = " (%dx%d "
|
||||
if image.format:
|
||||
format = " (" + image.format + " %dx%d "
|
||||
return title + format % image.size + image.mode + ")"
|
||||
|
||||
if len(sys.argv) == 1:
|
||||
print("PIL Print 0.3/2003-05-05 -- print image files")
|
||||
print("Usage: pilprint files...")
|
||||
print("Options:")
|
||||
print(" -c colour printer (default is monochrome)")
|
||||
print(" -d debug (show available drivers)")
|
||||
print(" -p print via lpr (default is stdout)")
|
||||
print(" -P <printer> same as -p but use given printer")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
opt, argv = getopt.getopt(sys.argv[1:], "cdpP:")
|
||||
except getopt.error as v:
|
||||
print(v)
|
||||
sys.exit(1)
|
||||
|
||||
printerArgs = [] # print to stdout
|
||||
monochrome = 1 # reduce file size for most common case
|
||||
|
||||
for o, a in opt:
|
||||
if o == "-d":
|
||||
# debug: show available drivers
|
||||
Image.init()
|
||||
print(Image.ID)
|
||||
sys.exit(1)
|
||||
elif o == "-c":
|
||||
# colour printer
|
||||
monochrome = 0
|
||||
elif o == "-p":
|
||||
# default printer channel
|
||||
printerArgs = ["lpr"]
|
||||
elif o == "-P":
|
||||
# printer channel
|
||||
printerArgs = ["lpr", "-P%s" % a]
|
||||
|
||||
for filepath in argv:
|
||||
try:
|
||||
|
||||
im = Image.open(filepath)
|
||||
|
||||
title = description(filepath, im)
|
||||
|
||||
if monochrome and im.mode not in ["1", "L"]:
|
||||
im.draft("L", im.size)
|
||||
im = im.convert("L")
|
||||
|
||||
if printerArgs:
|
||||
p = subprocess.Popen(printerArgs, stdin=subprocess.PIPE)
|
||||
fp = p.stdin
|
||||
else:
|
||||
fp = sys.stdout
|
||||
|
||||
ps = PSDraw.PSDraw(fp)
|
||||
|
||||
ps.begin_document()
|
||||
ps.setfont("Helvetica-Narrow-Bold", 18)
|
||||
ps.text((letter[0], letter[3]+24), title)
|
||||
ps.setfont("Helvetica-Narrow-Bold", 8)
|
||||
ps.text((letter[0], letter[1]-30), VERSION)
|
||||
ps.image(letter, im)
|
||||
ps.end_document()
|
||||
|
||||
if printerArgs:
|
||||
fp.close()
|
||||
|
||||
except:
|
||||
print("cannot print image", end=' ')
|
||||
print("(%s:%s)" % (sys.exc_info()[0], sys.exc_info()[1]))
|
|
@ -1,94 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# The Python Imaging Library
|
||||
# $Id$
|
||||
#
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version_info[0] > 2:
|
||||
import tkinter
|
||||
else:
|
||||
import Tkinter as tkinter
|
||||
|
||||
from PIL import Image, ImageTk
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# an image animation player
|
||||
|
||||
class UI(tkinter.Label):
|
||||
|
||||
def __init__(self, master, im):
|
||||
self.im = im
|
||||
if isinstance(self.im, list):
|
||||
# list of images
|
||||
im = self.im.pop(0)
|
||||
|
||||
if im.mode == "1":
|
||||
self.image = ImageTk.BitmapImage(im, foreground="white")
|
||||
else:
|
||||
self.image = ImageTk.PhotoImage(im)
|
||||
|
||||
tkinter.Label.__init__(self, master, image=self.image, bg="black", bd=0)
|
||||
|
||||
self.update()
|
||||
|
||||
duration = im.info.get("duration", 100)
|
||||
self.after(duration, self.next)
|
||||
|
||||
def next(self):
|
||||
|
||||
if isinstance(self.im, list):
|
||||
|
||||
try:
|
||||
im = self.im[0]
|
||||
del self.im[0]
|
||||
self.image.paste(im)
|
||||
except IndexError:
|
||||
return # end of list
|
||||
|
||||
else:
|
||||
|
||||
try:
|
||||
im = self.im
|
||||
im.seek(im.tell() + 1)
|
||||
self.image.paste(im)
|
||||
except EOFError:
|
||||
return # end of file
|
||||
|
||||
duration = im.info.get("duration", 100)
|
||||
self.after(duration, self.next)
|
||||
|
||||
self.update_idletasks()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# script interface
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
if not sys.argv[1:]:
|
||||
print("Syntax: python player.py imagefile(s)")
|
||||
sys.exit(1)
|
||||
|
||||
filename = sys.argv[1]
|
||||
|
||||
root = tkinter.Tk()
|
||||
root.title(filename)
|
||||
|
||||
if len(sys.argv) > 2:
|
||||
# list of images
|
||||
print("loading...")
|
||||
im = []
|
||||
for filename in sys.argv[1:]:
|
||||
im.append(Image.open(filename))
|
||||
else:
|
||||
# sequence
|
||||
im = Image.open(filename)
|
||||
|
||||
UI(root, im).pack()
|
||||
|
||||
root.mainloop()
|
|
@ -1,80 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# The Python Imaging Library
|
||||
# $Id$
|
||||
#
|
||||
# this demo script illustrates how a 1-bit BitmapImage can be used
|
||||
# as a dynamically updated overlay
|
||||
#
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version_info[0] > 2:
|
||||
import tkinter
|
||||
else:
|
||||
import Tkinter as tkinter
|
||||
|
||||
from PIL import Image, ImageTk
|
||||
|
||||
#
|
||||
# an image viewer
|
||||
|
||||
|
||||
class UI(tkinter.Frame):
|
||||
def __init__(self, master, im, value=128):
|
||||
tkinter.Frame.__init__(self, master)
|
||||
|
||||
self.image = im
|
||||
self.value = value
|
||||
|
||||
self.canvas = tkinter.Canvas(self, width=im.size[0], height=im.size[1])
|
||||
self.backdrop = ImageTk.PhotoImage(im)
|
||||
self.canvas.create_image(0, 0, image=self.backdrop, anchor=tkinter.NW)
|
||||
self.canvas.pack()
|
||||
|
||||
scale = tkinter.Scale(self, orient=tkinter.HORIZONTAL, from_=0, to=255,
|
||||
resolution=1, command=self.update_scale,
|
||||
length=256)
|
||||
scale.set(value)
|
||||
scale.bind("<ButtonRelease-1>", self.redraw)
|
||||
scale.pack()
|
||||
|
||||
# uncomment the following line for instant feedback (might
|
||||
# be too slow on some platforms)
|
||||
# self.redraw()
|
||||
|
||||
def update_scale(self, value):
|
||||
self.value = float(value)
|
||||
|
||||
self.redraw()
|
||||
|
||||
def redraw(self, event=None):
|
||||
|
||||
# create overlay (note the explicit conversion to mode "1")
|
||||
im = self.image.point(lambda v, t=self.value: v >= t, "1")
|
||||
self.overlay = ImageTk.BitmapImage(im, foreground="green")
|
||||
|
||||
# update canvas
|
||||
self.canvas.delete("overlay")
|
||||
self.canvas.create_image(0, 0, image=self.overlay, anchor=tkinter.NW,
|
||||
tags="overlay")
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# main
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: thresholder file")
|
||||
sys.exit(1)
|
||||
|
||||
root = tkinter.Tk()
|
||||
|
||||
im = Image.open(sys.argv[1])
|
||||
|
||||
if im.mode != "L":
|
||||
im = im.convert("L")
|
||||
|
||||
# im.thumbnail((320,200))
|
||||
|
||||
UI(root, im).pack()
|
||||
|
||||
root.mainloop()
|
|
@ -1,55 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# The Python Imaging Library
|
||||
# $Id$
|
||||
#
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version_info[0] > 2:
|
||||
import tkinter
|
||||
else:
|
||||
import Tkinter as tkinter
|
||||
|
||||
from PIL import Image, ImageTk
|
||||
|
||||
#
|
||||
# an image viewer
|
||||
|
||||
|
||||
class UI(tkinter.Label):
|
||||
|
||||
def __init__(self, master, im):
|
||||
|
||||
if im.mode == "1":
|
||||
# bitmap image
|
||||
self.image = ImageTk.BitmapImage(im, foreground="white")
|
||||
tkinter.Label.__init__(self, master, image=self.image, bd=0,
|
||||
bg="black")
|
||||
|
||||
else:
|
||||
# photo image
|
||||
self.image = ImageTk.PhotoImage(im)
|
||||
tkinter.Label.__init__(self, master, image=self.image, bd=0)
|
||||
|
||||
#
|
||||
# script interface
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
if not sys.argv[1:]:
|
||||
print("Syntax: python viewer.py imagefile")
|
||||
sys.exit(1)
|
||||
|
||||
filename = sys.argv[1]
|
||||
|
||||
root = tkinter.Tk()
|
||||
root.title(filename)
|
||||
|
||||
im = Image.open(filename)
|
||||
|
||||
UI(root, im).pack()
|
||||
|
||||
root.mainloop()
|
2
setup.py
2
setup.py
|
@ -9,7 +9,6 @@
|
|||
# ------------------------------
|
||||
from __future__ import print_function
|
||||
|
||||
import glob
|
||||
import os
|
||||
import platform as plat
|
||||
import re
|
||||
|
@ -796,7 +795,6 @@ try:
|
|||
ext_modules=[Extension("PIL._imaging", ["_imaging.c"])],
|
||||
include_package_data=True,
|
||||
packages=find_packages(),
|
||||
scripts=glob.glob("Scripts/*.py"),
|
||||
test_suite='nose.collector',
|
||||
keywords=["Imaging", ],
|
||||
license='Standard PIL License',
|
||||
|
|
Loading…
Reference in New Issue
Block a user