code: def createimage(app, srcdir, buildpath):
      
      text = app.config.sphinxmark_text
  
      # draw transparent background
      width = app.config.sphinxmark_text_width
      height = app.config.sphinxmark_text_spacing
      img = Image.new('RGBA', (width, height), (255, 255, 255, 0))
      d = ImageDraw.Draw(img)
  
      # set font
      fontfile = os.path.join(srcdir, 'arial.ttf')
      font = ImageFont.truetype(fontfile, app.config.sphinxmark_text_size)
  
      # set x y location for text
      xsize, ysize = d.textsize(text, font)
      LOG.debug('[sphinxmark] x = ' + str(xsize) + '\ny = ' + str(ysize))
      x = (width / 2) - (xsize / 2)
      y = (height / 2) - (ysize / 2)
  
      # add text to image
      color = app.config.sphinxmark_text_color
      d.text((x, y), text, font=font, fill=color)
  
      # set opacity
      img.putalpha(app.config.sphinxmark_text_opacity)
  
      # rotate image
      img = img.rotate(app.config.sphinxmark_text_rotation)
  
      # save image
      imagefile = 'textmark_' + text + '.png'
      imagepath = os.path.join(buildpath, imagefile)
      img.save(imagepath, 'PNG')
      LOG.debug('[sphinxmark] Image saved to: ' + imagepath)
  
      return(imagefile)
docs: Create PNG image from string.