<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def optimize_image(arg):
 """Optimize a given image from a filename."""

    try:
        filename, image_format, settings = arg

        Settings.update(settings)

        format_module, nag_about_gifs = _get_format_module(image_format)

        if format_module is None:
            if Settings.verbose > 1:
                print(filename, image_format)  # image.mode)
                print("\tFile format not selected.")
            return None

        report_stats = _optimize_with_progs(format_module, filename,
                                            image_format)
        report_stats.nag_about_gifs = nag_about_gifs
        stats.report_saved(report_stats)
        return report_stats
    except Exception as exc:
        print(exc)
        traceback.print_exc()
        return stats.ReportStats(filename, error="Optimizing Image")