code: public static void setCompressionType(ImageWriteParam param, BufferedImage image)
      {
          // avoid error: first compression type is RLE, not optimal and incorrect for color images
          // TODO expose this choice to the user?
          if (image.getType() == BufferedImage.TYPE_BYTE_BINARY &&
              image.getColorModel().getPixelSize() == 1)
          {
              param.setCompressionType("CCITT T.6");
          }
          else
          {
              param.setCompressionType("LZW");
          }
      }
docs: Sets the ImageIO parameter compression type based on the given image.
  @param image buffered image used to decide compression type
  @param param ImageIO write parameter to update