def save_pars(img, savefile=None, quiet=False):
    """Save parameters to a file.

    The save file is a "pickled" opts dictionary.
    """
    try:
        import cPickle as pickle
    except ImportError:
        import pickle
    from . import tc
    import sys
    if savefile is None or savefile == '':
        savefile = img.opts.filename + '.pybdsf.sav'
    pars = img.opts.to_dict()
    output = open(savefile, 'wb')
    pickle.dump(pars, output, protocol=0)
    output.close()
    if not quiet:
        print("--> Saved parameters to file '" + savefile + "'.")
