docs: def _generate_image(self, matrix, width, height, padding, foreground, background, image_format):
          """
          Generates an identicon image in requested image format out of the passed
          block matrix, with the requested width, height, padding, foreground
          colour, background colour, and image format.
  
          Arguments:
  
            matrix - Matrix describing which blocks in the identicon should be
            painted with foreground (background if inverted) colour.
  
            width - Width of resulting identicon image in pixels.
  
            height - Height of resulting identicon image in pixels.
  
            padding - Tuple describing padding around the generated identicon. The
            tuple should consist out of four values, where each value is the
            number of pixels to use for padding. The order in tuple is: top,
            bottom, left, right.
  
            foreground - Colour which should be used for foreground (filled
            blocks), represented as a string of format supported by the
            PIL.ImageColor module.
  
            background - Colour which should be used for background and padding,
            represented as a string of format supported by the PIL.ImageColor
            module.
  
            image_format - Format to use for the image. Format needs to be
            supported by the Pillow library.
  
          Returns:
  
            Identicon image in requested format, returned as a byte list.
          """
  
          # Set-up a new image object, setting the background to provided value.
          image = Image.new("RGBA", (width + padding[2] + padding[3], height + padding[0] + padding[1]), background)
  
          # Set-up a draw image (for drawing the blocks).
          draw = ImageDraw.Draw(image)
  
          # Calculate the block widht and height.
          block_width = width // self.columns
          block_height = height // self.rows
  
          # Go through all the elements of a matrix, and draw the rectangles.
          for row, row_columns in enumerate(matrix):
              for column, cell in enumerate(row_columns):
                  if cell:
                      # Set-up the coordinates for a block.
                      x1 = padding[2] + column * block_width
                      y1 = padding[0] + row * block_height
                      x2 = padding[2] + (column + 1) * block_width - 1
                      y2 = padding[0] + (row + 1) * block_height - 1
  
                      # Draw the rectangle.
                      draw.rectangle((x1, y1, x2, y2), fill=foreground)
  
          # Set-up a stream where image will be saved.
          stream = BytesIO()
  
          if image_format.upper() == "JPEG":
              image = image.convert(mode="RGB")
  
          # Save the image to stream.
          try:
              image.save(stream, format=image_format, optimize=True)
          except KeyError:
              raise ValueError("Pillow does not support requested image format: %s" % image_format)
          image_raw = stream.getvalue()
          stream.close()
  
          # Return the resulting image.
          return image_raw