code: public static BufferedImage joinImages(List<BufferedImage> images, int lines, int height, int minHeight, boolean scale) {
  
        // Array of input images.
        List<BufferedImage> input = new ArrayList<BufferedImage>();
  
        int actualHeight = height;
  
        // if not scale, start from 1, so will use the max height of images, not more than that.
        if (!scale) {
          actualHeight = 1;
        }
  
        for (BufferedImage imageToJoin : images) {
          try {
            BufferedImage img = MyImageUtils.trim(imageToJoin);
  
            if (scale) {
              actualHeight = Integer.min(actualHeight, img.getHeight());
            } else {
              actualHeight = Integer.max(actualHeight, img.getHeight());
            }
            input.add(img);
  
          } catch (Exception x) {
            x.printStackTrace();
          }
        }
  
        // minimum height for the posts is 480
        if (scale && actualHeight < minHeight 
            && input.size() > 0) {
          actualHeight = minHeight;
        }
  
        int totalWidth = 0;
        List<BufferedImage> fixedInput = new ArrayList<BufferedImage>();
        for (BufferedImage img : input) {
          BufferedImage newImg = img;
          if (scale && img.getHeight() > actualHeight) {
            newImg = MyImageUtils.resizeToHeight(img, actualHeight);
          }
  
          fixedInput.add(newImg);
  
          totalWidth += newImg.getWidth();
        }
  
        // Create the output image and fill with white.
        
        BufferedImage output = getWhiteImage(actualHeight * lines, totalWidth / lines);
        drawImages(lines, scale, input, actualHeight, output.getGraphics());
        
        return output;
    }
docs: Join images
  @param images Images to join
  @param lines Total of lines
  @param height Image height to scale
  @param minHeight Minimum height of image.
  @param scale If should scale images to fit
  @return Joined image