Beispiel #1
0
def main():
    #Asking for an image to use for the conversions
    filename = raw_input("Enter the filename of a gif: ")
    image = Image(filename)
    img = image.clone()
    gewd = False
    while not gewd:
        #Printing and asking for options
        print "%-2d%s" % (0, "black and white conversion")
        print "%-2d%s" % (1, "inverse conversion")
        print "%-2d%s" % (2, "sepia conversion")
        print "%-2d%s" % (3, "reset image")
        print "%-2d%s" % (4, "load new image")
        print "%-2d%s" % (5, "quit")
        print "\n"
        option = raw_input("Enter an option: ")
        correctInput = False
        while correctInput == False:
            #If the option is a number between 0 and 3
            if not option.isalpha() and int(option) >= 0 and int(option) < 6:
                print "Thanks for coherent input bro!"
                correctInput = True
            else:
                option = raw_input(
                    "Enter a numerical option BETWEEN 0 and 5: ")
        option = int(option)
        if option != 5:
            #If the user has wished the image to be restored to its initial state
            if option == 3:
                #Cloning the original image and overwriting all previously done conversions
                img = image.clone()
            elif option == 4:
                filename = raw_input(
                    "Enter a filename of the image you wish to alter(gif please): "
                )
                image = Image(filename)
                img = image.clone()
            else:
                #Perform other tasks on the current image
                computeOptions(option, img)
            print "Close the image to continue!"
            img.draw()
        else:
            gewd = True
            print "\nHave a nice day!"
Beispiel #2
0
from images import Image

image = Image("smokey.gif")
(r, g, b) = image.getPixel(0, 0)


def grayscale(image):
    for y in range(image.getHeight()):
        for x in range(image.getWidth()):
            (r, g, b) = image.getPixel(x, y)
            r = int(r * 0.299)
            g = int(g * 0.587)
            b = int(b * 0.114)
            lum = r + g + b
            image.setPixel(x, y, (lum, lum, lum))


average = (r + g + b) // 3

image.draw()
newImage = image.clone()
newImage.draw()
grayscale(newImage)
newImage.draw()
image.draw()