def get_new_dim(imgw, imgh, max_dim=400):
  """Get new image dimension with maximum constraint.

  Args:
    imgw: image width.
    imgh: image height.
    max_dim: maximum image dimension after.
  Returns:
    new img width and height.
  """
  max_val = max(imgw, imgh)
  ratio = max_val / max_dim
  new_imgw = int(imgw / ratio)
  new_imgh = int(imgh / ratio)
  return new_imgw, new_imgh
  # new_imgw = imgw
  # new_imgh = imgh
  # if imgw > imgh:
  #   new_imgw = max_dim
  #   new_imgh = imgh * max_dim // imgw
  # if imgh > imgw:
  #   new_imgh = max_dim
  #   new_imgw = imgw * max_dim // imgh
  # return new_imgw, new_imgh