2013-04-21 10:38:36 +04:00
|
|
|
#!/usr/bin/env python
|
2010-07-31 06:52:47 +04:00
|
|
|
#
|
|
|
|
# The Python Imaging Library
|
|
|
|
# $Id$
|
|
|
|
#
|
|
|
|
# this demo script creates four windows containing an image and a slider.
|
|
|
|
# drag the slider to modify the image.
|
|
|
|
#
|
|
|
|
|
2017-03-24 11:42:58 +03:00
|
|
|
import sys
|
|
|
|
|
|
|
|
if sys.version_info[0] > 2:
|
|
|
|
import tkinter
|
|
|
|
else:
|
|
|
|
import Tkinter as tkinter
|
2012-10-17 06:58:29 +04:00
|
|
|
|
2010-07-31 06:52:47 +04:00
|
|
|
from PIL import Image, ImageTk, ImageEnhance
|
|
|
|
|
|
|
|
#
|
|
|
|
# enhancer widget
|
|
|
|
|
2015-04-24 02:41:33 +03:00
|
|
|
|
2017-03-24 11:42:58 +03:00
|
|
|
class Enhance(tkinter.Frame):
|
2010-07-31 06:52:47 +04:00
|
|
|
def __init__(self, master, image, name, enhancer, lo, hi):
|
2017-03-24 11:42:58 +03:00
|
|
|
tkinter.Frame.__init__(self, master)
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
# set up the image
|
|
|
|
self.tkim = ImageTk.PhotoImage(image.mode, image.size)
|
|
|
|
self.enhancer = enhancer(image)
|
2015-04-24 02:41:33 +03:00
|
|
|
self.update("1.0") # normalize
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
# image window
|
2017-03-24 11:42:58 +03:00
|
|
|
tkinter.Label(self, image=self.tkim).pack()
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
# scale
|
2017-03-24 11:42:58 +03:00
|
|
|
s = tkinter.Scale(self, label=name, orient=tkinter.HORIZONTAL,
|
2010-07-31 06:52:47 +04:00
|
|
|
from_=lo, to=hi, resolution=0.01,
|
|
|
|
command=self.update)
|
|
|
|
s.set(self.value)
|
|
|
|
s.pack()
|
|
|
|
|
|
|
|
def update(self, value):
|
2016-05-10 16:07:16 +03:00
|
|
|
self.value = float(value)
|
2010-07-31 06:52:47 +04:00
|
|
|
self.tkim.paste(self.enhancer.enhance(self.value))
|
|
|
|
|
|
|
|
#
|
|
|
|
# main
|
|
|
|
|
2016-05-10 17:35:37 +03:00
|
|
|
if len(sys.argv) != 2:
|
|
|
|
print("Usage: enhancer file")
|
|
|
|
sys.exit(1)
|
|
|
|
|
2017-03-24 11:42:58 +03:00
|
|
|
root = tkinter.Tk()
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
im = Image.open(sys.argv[1])
|
|
|
|
|
|
|
|
im.thumbnail((200, 200))
|
|
|
|
|
|
|
|
Enhance(root, im, "Color", ImageEnhance.Color, 0.0, 4.0).pack()
|
2017-03-24 11:42:58 +03:00
|
|
|
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()
|
2010-07-31 06:52:47 +04:00
|
|
|
|
|
|
|
root.mainloop()
|