The module also provides a number of factory functions, including functions to load images from files, and to create new images. mkdir ( output_dir ) try : for file in os. The Image module provides a class with the same name which is used to represent a PIL image. height )) else : size = DEFAULT_SIZE if not os. output_dir else : output_dir = dir + '/resized' if args. input_dir else : input_dir = dir + '/images' if args. add_argument ( '-t', '-height', help = 'Resized Height' ) args = parser. add_argument ( '-w', '-width', help = 'Resized Width' ) parser. add_argument ( '-o', '-output_dir', help = 'Full Output Path' ) parser. add_argument ( '-i', '-input_dir', help = 'Full Input Path' ) parser. We will need to import argparse before setting up our command-line arguments: We can also include parameters for the height and width of our resized images. This will give use the ability to do things like pass in the directory in which our existing images are stored, and pass in another directory of where we would like our new, resized images to go. That being said, in order to make this usable without having to change the script every time, we will use argparse to allow passing in parameters through the command line. We now have a working bulk image resize process. Running the script should successfully resize any images that have been placed in our images folder. save ( new_file ) except IOError : print ( "unable to resize image ". LANCZOS ) new_file = output_dir + "/" + outfile + extension img. open ( input_dir + '/' + infile ) img = img. splitext ( infile ) + "_resized" extension = os. def resize_image ( input_dir, infile, output_dir = "resized", size = ( 320, 180 )): outfile = os.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |