# Bruce Maxwell # spring 2011 # Updated by Stephanie Taylor Fall 2014 # Updated by Bruce Maxwell Fall 2017 # project 4 # Test function for the placeImage function # import sys import graphics import filter # takes in a filename of a ppm image # creates a new Image twice as wide and copies # the original image into it twice def test( argv ): # test if the user provided a filename if len(argv) < 2: print('usage: %s ' % (argv[0])) exit() filename = argv[1] # see if we can open the file try: srcImage = graphics.Image( graphics.Point(0,0), filename ) except: print('error: unable to open file %s' % (filename)) exit() # create a new empty image that is the same height and twice as wide dstImage = graphics.Image( graphics.Point(0,0), srcImage.getWidth() * 2, srcImage.getHeight() ) # place the original image into the empty image in two places filter.placeImage( dstImage, srcImage, 0, 0 ) filter.placeImage( dstImage, srcImage, srcImage.getWidth(), 0 ) # save the new image to the file duplicate.ppm dstImage.save( 'duplicate.ppm' ) print("Saved the new image to duplicate.ppm") return # call the test function with the command line strings as the argument if __name__ == "__main__": test( sys.argv )