def get_relative_path_from_img_id(img_id, variant_label=None, ext=None, create_dirs=False):
profile, base_name = img_id.split('<STR_LIT::>', <NUM_LIT:1>)<EOL>conf = get_profile_configs(profile)<EOL>if not variant_label:<EOL><INDENT>status_suffix = dju_settings.DJU_IMG_UPLOAD_MAIN_SUFFIX<EOL><DEDENT>else:<EOL><INDENT>status_suffix = dju_settings.DJU_IMG_UPLOAD_VARIANT_SUFFIX<EOL><DEDENT>name, file_ext = os.path.splitext(base_name)<EOL>prefix = '<STR_LIT>'<EOL>if name.startswith(dju_settings.DJU_IMG_UPLOAD_TMP_PREFIX):<EOL><INDENT>name = name[len(dju_settings.DJU_IMG_UPLOAD_TMP_PREFIX):]<EOL>prefix = dju_settings.DJU_IMG_UPLOAD_TMP_PREFIX<EOL><DEDENT>name_parts = name.split('<STR_LIT:_>', <NUM_LIT:2>)<EOL>name = '<STR_LIT>'.format(<EOL>name=name,<EOL>status_suffix=status_suffix,<EOL>hash=get_hash('<STR_LIT:_>'.join(name_parts[:<NUM_LIT:2>]), variant_label=variant_label)<EOL>)<EOL>if variant_label:<EOL><INDENT>name += '<STR_LIT:_>' + variant_label<EOL><DEDENT>if ext:<EOL><INDENT>file_ext = ext<EOL><DEDENT>elif variant_label:<EOL><INDENT>for var_conf in conf['<STR_LIT>']:<EOL><INDENT>var_conf_label = var_conf['<STR_LIT>'] or get_variant_label(var_conf)<EOL>if var_conf_label == variant_label:<EOL><INDENT>if var_conf['<STR_LIT>']:<EOL><INDENT>file_ext = var_conf['<STR_LIT>'].lower()<EOL><DEDENT>break<EOL><DEDENT><DEDENT><DEDENT>if file_ext and not file_ext.startswith('<STR_LIT:.>'):<EOL><INDENT>file_ext = '<STR_LIT:.>' + file_ext<EOL><DEDENT>relative_path = os.path.join(<EOL>dju_settings.DJU_IMG_UPLOAD_SUBDIR,<EOL>conf['<STR_LIT>'],<EOL>name_parts[<NUM_LIT:0>][-<NUM_LIT:2>:],<EOL>(prefix + name + file_ext)<EOL>).replace('<STR_LIT:\\>', '<STR_LIT:/>')<EOL>if create_dirs:<EOL><INDENT>path = media_path(relative_path)<EOL>make_dirs_for_file_path(path, mode=dju_settings.DJU_IMG_CHMOD_DIR)<EOL><DEDENT>return relative_path<EOL>
Returns path to file relative MEDIA_URL.