docs: def extract_images(data, plugin):
      """
      extracts base64 encoded images from drag and drop actions in browser and saves
      those images as plugins
      """
      if not settings.TEXT_SAVE_IMAGE_FUNCTION:
          return data
      tree_builder = html5lib.treebuilders.getTreeBuilder('dom')
      parser = html5lib.html5parser.HTMLParser(tree=tree_builder)
      dom = parser.parse(data)
      found = False
      for img in dom.getElementsByTagName('img'):
          src = img.getAttribute('src')
          if not src.startswith('data:'):
              # nothing to do
              continue
          width = img.getAttribute('width')
          height = img.getAttribute('height')
          # extract the image data
          data_re = re.compile(r'data:(?P<mime_type>[^"]*);(?P<encoding>[^"]*),(?P<data>[^"]*)')
          m = data_re.search(src)
          dr = m.groupdict()
          mime_type = dr['mime_type']
          image_data = dr['data']
          if mime_type.find(';'):
              mime_type = mime_type.split(';')[0]
          try:
              image_data = base64.b64decode(image_data)
          except Exception:
              image_data = base64.urlsafe_b64decode(image_data)
          try:
              image_type = mime_type.split('/')[1]
          except IndexError:
              # No image type specified -- will convert to jpg below if it's valid image data
              image_type = ''
          image = BytesIO(image_data)
          # genarate filename and normalize image format
          if image_type == 'jpg' or image_type == 'jpeg':
              file_ending = 'jpg'
          elif image_type == 'png':
              file_ending = 'png'
          elif image_type == 'gif':
              file_ending = 'gif'
          else:
              # any not "web-safe" image format we try to convert to jpg
              im = Image.open(image)
              new_image = BytesIO()
              file_ending = 'jpg'
              im.save(new_image, 'JPEG')
              new_image.seek(0)
              image = new_image
          filename = u'%s.%s' % (uuid.uuid4(), file_ending)
          # transform image into a cms plugin
          image_plugin = img_data_to_plugin(
              filename, image, parent_plugin=plugin, width=width, height=height
          )
          # render the new html for the plugin
          new_img_html = plugin_to_tag(image_plugin)
          # replace the original image node with the newly created cms plugin html
          img.parentNode.replaceChild(parser.parseFragment(new_img_html).childNodes[0], img)
          found = True
      if found:
          return u''.join([y.toxml() for y in dom.getElementsByTagName('body')[0].childNodes])
      else:
          return data