# starter program for image manipulation program # # written by e.bonakdarian nov 2009 # updated mar 2010 # updated nov 2010 # updated jun 2011 # import Image # choices QUIT = 0 DIAGONAL = 1 STRIPE_HORIZ = 2 STRIPE_VERTICAL = 3 COLOR_BLUE = 4 ##################################################### def Diag(img, pixel_color): # put a diagonal line across the image in the # specified color # # *** ALREADY WORKING - PLEASE DO NOT MODIFY *** pix_ar = img.load() # load image into 2D array cols = img.size[0] # number of columns rows = img.size[1] # number of rows for col in range(cols): # our nested loop for row in range(rows): if row == col: pix_ar[col, row] = pixel_color ##################################################### def Stripe_H(img, pixel_color): # put a line in the specified color across the # image every other line. pix_ar = img.load() # load image into 2D array cols = img.size[0] # number of columns rows = img.size[1] # number of rows print 'not finished' ##################################################### def Stripe_V(img, pixel_color): # put a line in the specified color down the # image every other line. pix_ar = img.load() # load image into 2D array cols = img.size[0] # number of columns rows = img.size[1] # number of rows print 'not finished' ##################################################### def ColorIt_Blue(img): # set all the pixels to blue pix_ar = img.load() # load image into 2D array cols = img.size[0] # number of columns rows = img.size[1] # number of rows print 'not finished' ####################################################### def display_menu(): # displays the menu, and returns the user selection print '\t=========================================' print '\tMenu' print '\t=========================================' print '\t1) Diagonal line' #done for you print '\t2) Stripe horizontal (every other row)' print '\t3) Stripe vertical (every other column)' print '\t4) Color image solid blue' print '\t=========================================' print '\t0) Quit' selection = input('\n\tEnter your choice: ') return selection ####################################################### def main(): # our main program choice = display_menu() if choice == QUIT: print 'Quitting program.' else: #load image im = Image.open('c:/esmail/pie.jpg') pixel_color = 255, 0, 0 # red RGB pixel if choice == DIAGONAL: Diag(im, pixel_color) elif choice == STRIPE_HORIZ: Stripe_H(im, pixel_color) elif choice == STRIPE_VERTICAL: Stripe_V(im, pixel_color) elif choice == COLOR_BLUE: ColorIt_Blue(im) else: print 'Error: Unknown choice: ', choice im.show() if __name__ == '__main__': main()