[Image-SIG] Something other than .show()

Joseph Quigley cpu.crazy at gmail.com
Sat Jul 2 21:32:28 CEST 2005


Thanks! You guys made this possible (well, a fast quick image loading possible).
Here's my source code (the program's not finished but this works great):

import Image
import imghdr
import ImageTk
import os
import Tkinter

print "\n" * 100
print "Jimage Reader 1.0\n"

def imgshow(file):
    im = Image.open(file)
    window = Tkinter.Tk()
    window.tkIm = ImageTk.PhotoImage(im)
    window.label = Tkinter.Label(window, image=window.tkIm)
    window.label.pack()
    window.info = Tkinter.Label(window, text="Jimage Reader 1.0
Displaying: " + os.getcwd() + os.sep + open.img_name)
    window.info.pack()
    window.mainloop()

def help():
    while True:
        ask = raw_input("Help>> ")
# Displaying and image        
        if "show" in ask:
            print """\nHow to display the picture.
To display the picture, type 'dsp' (without the quotes) at the console.\n"""
        elif "display" in ask:
            print """\nHow to display the picture.
To display the picture, type 'dsp' (without the quotes) at the console.\n"""
        elif "open" in ask:
            print """\nHow to display the picture.
To display the picture, type 'dsp' (without the quotes) at the console.\n"""
        elif "see" in ask:
            print """\nHow to display the picture.
To display the picture, type 'dsp' (without the quotes) at the console.\n"""

# Rotating an image.
        elif "flip" in ask:
            print """\nHow to rotate an image.
Type 'rotate' (without the quotes) at the console.\n"""
        elif "rotate" in ask:
            print """\nHow to rotate an image.
Type 'rotate' (without the quotes) at the console.\n"""

        elif "sideways" in ask:
            print """\nHow to rotate an image.
Type 'rotate' (without the quotes) at the console.\n"""

        elif "upside down" in ask:
            print """\nHow to rotate an image.
Type 'rotate' (without the quotes) at the console.\n"""

        elif ask == "back()":
            print "\n" * 100
            break

# Other stuff not found
        else:
            print "No help for your topic (%s) was found." % (ask)
            
            
def quit():
    raise SystemExit

def save():
    filename = raw_input("File name to save: ")
    if ".gif" or ".GIF" in filename:
        open.im.save(filename, "GIF")
    elif ".jpg" or ".jpeg" or ".JPG" or ".JPEG" in filename:
          open.im.save(filename, "JPEG")

class open:
    while True:
        img_name = raw_input("\nImage name (including extention): ")
        try:
            img_name
        except KeyboardInterrupt:
            quit()
        except TypeError:
            quit()

        try:
            im = Image.open(img_name)
        except IOError:
            print "\nFile not found. Try again."
            continue
        print "\nFile loaded sucessfully.\n"
        break

while True:
    m_m = raw_input("Jimage Console. Type 'h' for help.\n> ")
    try:
        m_m
    except KeyboardInterrupt:
        raise SystemExit
    if m_m == "help":
        help()
    elif m_m == "dsp":
        imgshow(open.img_name)        
    elif m_m == "rotate":
        while True:
            try:
                angle = int(raw_input("\nRotate by: "))
            except ValueError:
                print "Only digits are accepted. Eg: 180 instead of
one hundred eighty."
                continue
            if ".gif" or ".GIF" in filename:
                    open.im.rotate(angle).save("tmp", "GIF")
            elif ".jpg" or ".jpeg" or ".JPG" or ".JPEG" in filename:
                    open.im.rotate(angle).save("tmp", "JPEG")
            imgshow("tmp")
            
            ok = raw_input("Is this ok? (Y/N): ")
            if ((ok == "Y") or ("y" == ok)):
                break
            else:
                continue
        while True:
            save = raw_input("Save? (Y/N): ")
            if ((save == "n") or ("N" == save)):
                break
            else:
                filename = raw_input("File name to save: ")
                if ".gif" or ".GIF" in filename:
                    open.im.rotate(angle).save(filename, "GIF")
                elif ".jpg" or ".jpeg" or ".JPG" or ".JPEG" in filename:
                      open.im.rotate(angle).save(filename, "JPEG")
            print "\n\n"
            break
    elif m_m == "open":
        while True:
            open.img_name = raw_input("\nImage name (including extention): ")
            try:
                open.img_name
            except KeyboardInterrupt:
                quit()
            except TypeError:
                quit()
    
            try:
                open.im = Image.open(open.img_name)
            except IOError:
                print "\nFile not found. Try again."
                continue
            print "\nFile loaded sucessfully.\n"
            break
            imgshow(open.img_name)
    elif m_m == "exit":
        quit()   

Thanks again,

Joe


More information about the Image-SIG mailing list