docs: def parse_region(region, image_width, image_height):
      """
      Parse Region parameter to determine the rectangular portion of the full
      image to be returned, informed by the actual image dimensions.
      Returns (x, y, width, height):
          - x,y are pixel offsets into the image from the upper left
          - width, height are pixel dimensions for cropped image.
      """
      if region == 'full':
          # Return complete image, no cropping
          x, y, width, height = 0, 0, image_width, image_height
      elif region == 'square':
          square_size = min(image_width, image_height)
          # Generate x,y offsets to centre cropped image. This is not mandated
          # by the spec but is recommended as a sensible default.
          x = int((image_width - square_size) / 2)
          y = int((image_height - square_size) / 2)
          width = height = square_size
      elif region.startswith('pct:'):
          x_pct, y_pct, width_pct, height_pct = \
              parse_dimensions_string(region[4:], permit_floats=True)
          x, y, width, height = map(int, (
              x_pct / 100 * image_width,
              y_pct / 100 * image_height,
              width_pct / 100 * image_width,
              height_pct / 100 * image_height,
          ))
      else:
          x, y, width, height = parse_dimensions_string(region)
      # If region extends beyond original's dimensions, crop extends only to
      # image edge.
      width = min(width, image_width - x)
      height = min(height, image_height - y)
      return x, y, width, height