def encode_images(format_dict):
encoded = format_dict.copy()<EOL>pngdata = format_dict.get('<STR_LIT>')<EOL>if isinstance(pngdata, bytes) and pngdata[:<NUM_LIT:8>] == PNG:<EOL><INDENT>encoded['<STR_LIT>'] = encodestring(pngdata).decode('<STR_LIT:ascii>')<EOL><DEDENT>jpegdata = format_dict.get('<STR_LIT>')<EOL>if isinstance(jpegdata, bytes) and jpegdata[:<NUM_LIT:2>] == JPEG:<EOL><INDENT>encoded['<STR_LIT>'] = encodestring(jpegdata).decode('<STR_LIT:ascii>')<EOL><DEDENT>return encoded<EOL>
b64-encodes images in a displaypub format dict

    Perhaps this should be handled in json_clean itself?

    Parameters
    ----------

    format_dict : dict
        A dictionary of display data keyed by mime-type

    Returns
    -------

    format_dict : dict
        A copy of the same dictionary,
        but binary image data ('image/png' or 'image/jpeg')
        is base64-encoded.