コード例 #1
0
 def test_smoke(self):
     """
     Smoke test to make sure filmify_image runs without errors
     REQUIRES photo named test_photo.jpg to be in current directory
     """
     image_data = Image.open("test_photo.jpg")
     new_image_data = filmify_image(image_data)
     assert new_image_data
コード例 #2
0
def main():
    """Retrieves file entered, manipulates it and saves a copy with a new name"""
    # Parse options
    parser = optparse.OptionParser()
    parser.add_option(
        "-f",
        dest="filename",
        help="Picture to modify",
        metavar="FILE"
    )
    parser.add_option(
        "-s",
        dest='custom_string',
        help='String to be placed at the top of the film'
             'Default is Kodak'
    )
    (opts, args) = parser.parse_args()

    # Give user feedback if they forget an option and exit
    mandatory_options = ['filename']
    for option in mandatory_options:
        if not opts.__dict__[option]:
            print "Mandatory option is missing\n"
            parser.print_help()
            exit(-1)

    full_filename =  opts.filename
    if full_filename != None:
        try:
            image_data = Image.open(full_filename)
            new_image_data = filmify_image(image_data)
            add_text_header(new_image_data, text=opts.custom_string)
            safe_save(full_filename, new_image_data)
        except IOError:
            print "Can not modify " + full_filename
    else:
        print 'Must enter photo in this directory'