from PIL import Image def legal( v ) : ''' converts v to a legal RGB level; if v is negative, 0 is returned. if v exceeds 255, 255 is returned; otherwise, v is returned ''' pass def offset( pixel, x, y, z ) : ''' returns a new pixel by first decrementing the RGB values of pixel by x, y, and z respectively. to ensure the new pixel, the RGB values are run through legal() ''' pass def create_color_shift( original, x, y, z ) : ''' returns a new image that is a copy of the original, where a pixel in the new image is produced by using offset() on the corresponding original pixel with respect to x, y, and z ''' ow, oh = original.size # get dimensions of original nw, nh = ow, oh # new image has same dimensions new_image = Image.new( 'RGB', ( nw, nh ) ) # create new image for nx in range( 0, nw ) : # fill in every pixel of new image for ny in range( 0, nh ) : nspot = (nx, ny ) # set spot to be filled in new image ospot = nspot # use corresponding spot in original opixel = original.getpixel( ospot ) # get pixel at corresponding spot npixel = offset( opixel, x, y, z ) # shift that pixel using x, y, z offsets new_image.putpixel( nspot, npixel ) # set spot in new image return new_image # return color_shift if ( __name__ == '__main__' ) : import url TEST_URL = 'http://www.cs.virginia.edu/~cs1112/images/ml.png' original = url.get_image( TEST_URL ) result = create_color_shift( original, 25, -50, 75 ) result.save( "color-shift-ml.png" )