code: public ImageProcessor crop(ImageProcessor ip,
                                 String cropX,
                                 String cropY,
                                 String cropWidth,
                                 String cropHeight) {
          if (cropX != null && cropY != null) {
              try {
                  int x = Integer.parseInt(cropX);
                  int y = Integer.parseInt(cropY);
                  int width;
                  int height;
  
                  // if value for cropWidth is not given, just use the width of the image
                  if (cropWidth != null) {
                      width = Integer.parseInt(cropWidth);
                  } else {
                      width = ip.getWidth();
                  }
  
                  // if value for cropHeight is not given, just use the height of the image
                  if (cropHeight != null) {
                      height = Integer.parseInt(cropHeight);
                  } else {
                      height = ip.getHeight();
                  }
  
                  // if any value is negative, this causes ImageJ to explode, so just return
                  if (x < 0 || y < 0 || width < 0 || height < 0) {
                      return ip;
                  }
  
                  ip.setRoi(x, y, width, height);
                  ip = ip.crop();
              }
  
              // no need to do anything with number format exception since the servlet
              // returns only images; just return the original image
              catch (NumberFormatException e) {
              }
          }
  
          return ip;
      }
docs: Crops an image with supplied starting point and ending point.
  
  @param ip
  The image to crop cropX The starting x position; x=0 corresponds
  to left side of image cropY The starting y position; y=0
  corresponds to top of image cropWidth The width of the crop,
  starting from the above x cropHeight The height of the crop,
  starting from the above y
  @return The image cropped