public static BaseImage biCubicSmooth(BaseImage img, int width, int height) {
    if(width > img.getWidth() || height > img.getHeight()) {
      throw new IllegalStateException("Both width and height must be less then the current image!!");
    }

    int scaleFactor = 7;
    BaseImage nimg = img;
    BaseImage resizedImg;
    while(true) {
      int runWidth = width;
      int runHeight = height;
      if(nimg.getWidth() > width) {
        runWidth = nimg.getWidth()-Math.max(1, (nimg.getWidth()/scaleFactor)); 
        if(runWidth < width) {
          runWidth = width;
        }
      }

      if(nimg.getHeight() > height) {
        runHeight = nimg.getHeight()-Math.max(1, (nimg.getHeight()/scaleFactor)); 
        if(runHeight < height) {
          runHeight = height;
        }
      }
      resizedImg = nimg.resize(runWidth, runHeight, false, BaseImage.ScaleType.CUBIC);
      nimg = resizedImg;
      if(nimg.getWidth() == width && nimg.getHeight() == height) {
        break;
      }
    }
    return resizedImg;
  }