code: private static int getTrimmedHeight(BufferedImage img) {
      int width = img.getWidth();
      int height = img.getHeight();
      int trimmedHeight = 0;
  
      for (int i = 0; i < width; i++) {
        for (int j = height - 1; j >= 0; j--) {
          if (img.getRGB(i, j) != Color.WHITE.getRGB() && j > trimmedHeight) {
            trimmedHeight = j;
            break;
          }
        }
      }
  
      return trimmedHeight;
    }
docs: Get the last non-white Y point
  @param img Image in memory
  @return The trimmed height