def draw_text(self, target, vertical_position, horizontal_position, text,
                font_file=DEFAULT_FONT, font_size=DEFAULT_FONT_SIZE,
                color=DEFAULT_TEXT_COLOR,
                border_width=DEFAULT_BORDER_WIDTH,
                border_color=DEFAULT_BORDER_COLOR):
      # determine the original text size
      font = ImageFont.truetype(font_file, font_size)
      image = Image.new("RGBA", (1, 1))
      draw = ImageDraw.Draw(image)
      text_width, text_height = draw.textsize(text, font=font)
      del draw

      # draw text with border
      bordered_text_width = text_width + 2 * border_width
      bordered_text_height = text_height + 2 * border_width
      image = Image.new('RGBA', (bordered_text_width, bordered_text_height))
      draw = ImageDraw.Draw(image)
      for pos in self.get_points_for_hemming((border_width, border_width),
                                        border_width):
          draw.text(pos, text, font=font, fill=border_color)
      draw.text((border_width, border_width), text, font=font, fill=color)
      del draw

      # obtain bounding boxes for 2 images for later use
      bbox = target.getbbox()
      text_bbox = image.getbbox()

      # scale only if the text exceeds the width of the target image
      if bbox[2] < text_bbox[2]:
          scale = float(bbox[2]) / text_bbox[2]
          image = image.resize((int(text_bbox[2] * scale),
                                int(text_bbox[3] * scale)), Image.ANTIALIAS)
          text_bbox = image.getbbox()
      else:
          image = image.filter(ImageFilter.SMOOTH)

      # determine the paste position
      if vertical_position == self.TOP:
          pos_y = 0
      elif vertical_position == self.MIDDLE:
          pos_y = int(bbox[3] / 2 - text_bbox[3] / 2)
      elif vertical_position == self.BOTTOM:
          pos_y = bbox[3] - text_bbox[3]
      else:
          raise RuntimeError('Invalid vertical_position: {}'
                           .format(vertical_position))
      if horizontal_position == self.LEFT:
          pos_x = 0
      elif horizontal_position == self.MIDDLE:
          pos_x = int(bbox[2] / 2 - text_bbox[2] / 2)
      elif horizontal_position == self.RIGHT:
          pos_x = bbox[2] - text_bbox[2]
      else:
          raise RuntimeError('Invalid horizontal_position: {}'
                             .format(horizontal_position))

      target.paste(image , (pos_x, pos_y), image)
Reads input ckpt num_epochs times.
dataset/ETHPy150Open blynch/CloudMemeBackend/cloudmeme_image.py/CloudMemeImage.draw_text--crossover with--dataset/ETHPy150Open HamedMP/ImageFlow/example_project/input_data.py/inputs