code: def convert_image(
      image_name, text, pref=None, origin_folder=None, dest_folder=None
  ):
      """Convert text to proper html code for image_name.
      Optionally copy image from origin_folder to dest_folder."""
      # Copy the image if necessary
      if origin_folder is not None and dest_folder is not None:
          origin_file = os.path.join(origin_folder, image_name)
          dest_file = os.path.join(dest_folder, image_name)
          if not os.path.isfile(dest_file):
              os.makedirs(os.path.dirname(dest_file), exist_ok=True)
              shutil.copy(origin_file, dest_file)
      attrs = {
          "src": image_name
          if pref is None
          else os.path.join(pref, image_name)
      }
      for line in text.split("\n"):
          if _re_attr_rst.search(line) is not None:
              key, attr = _re_attr_rst.search(line).groups()
              attrs[key] = attr
      html = " ".join(
          [f'{key}="{value}"' for key, value in attrs.items()]
      )
      return f"<img {html}/>"
  
imports: import nbformat
  import os
  import re
  import shutil
label_desc: Use image node_id 9 for calling a global function with example usage: convert_image(image_name, text, pref, origin_folder, dest_folder) and returns: str, html, str