def convert(files, overwrite=False, extension=None, color=(0, 0, 0, 0)):
    '''Takes a list of files and pads each one to power-of-two dimensions.'''
    try:
        from PIL import Image
    except ImportError:
        logging.error("You must install the Python Imaging Library to use " + 
                      "this script.")
        sys.exit(1)

    # ---Validating arguments---
    if overwrite and extension:
        raise PotArgumentError("'overwrite' and 'extension' cannot both be "+
                               "passed.")
    elif not overwrite and not extension:
        raise PotArgumentError("Must pass either overwrite or extension.")
    elif not overwrite and not isinstance(extension, basestring):
        raise PotArgumentError("Extension must be string.")
    if len(color) != 4 or not (isinstance(color, list) or 
                               isinstance(color, tuple)):
        raise PotArgumentError("'color' must be length 4 tuple or list.")

    # ---Image manipulation---
    pots = [2 ** exp for exp in range(16)] #powersoftwo
    for image_file in files:
        image = Image.open(image_file)

        # ---Deciding new dimensions---
        width, height = get_dimensions(image.size, pots)
        if width == None or height == None:
            logging.warning("'%s' has too large dimensions, skipping." % 
                            os.path.basename(image_file))
            continue

        # ---Checking for transparency support---
        out_color = get_color(image.mode, image_file, color)
        if out_color == None:
            logging.warning("'%s' not an RGB or RGBA image, skipping." % 
                            os.path.basename(image_file))
            continue

        # ---Creating output---
        logging.info("'%s' is %dx%d, making new %dx%d image..." % 
                     (os.path.basename(image_file), image.size[0],
                      image.size[1], width, height))
        output = Image.new(image.mode, (width, height), out_color)
        output.paste(image, ((width - image.size[0]) / 2, 
                             (height - image.size[1]) / 2))
        # Be able to write new file with same mode as old file
        mode = os.stat(image_file).st_mode
        # ---Saving output---
        if overwrite:
            output.save(image_file, image.format)
            os.chmod(image_file, mode)
        else:
            image_file = os.path.splitext(image_file)
            output_file = image_file[0] + "." + extension + image_file[1]
            output.save(output_file, image.format)
            os.chmod(output_file, mode)
    return 0
Takes a list of files and pads each one to power-of-two dimensions.
recipes/Python/576416_Pad_images_poweroftwo/recipe-576416.py