code: private RenditionMetadata getVirtualRendition(RenditionMetadata rendition, long widthValue, long heightValue, double ratioValue) {
  
      long width = widthValue;
      long height = heightValue;
      double ratio = ratioValue;
  
      // if ratio is missing: calculate from given rendition
      if (ratio < MediaFormatHandler.RATIO_TOLERANCE) {
        ratio = (double)rendition.getWidth() / (double)rendition.getHeight();
      }
  
      // if height is missing - calculate from width
      if (height == 0 && width > 0) {
        height = (int)Math.round(width / ratio);
      }
  
      // if width is missing - calculate from height
      if (width == 0 && height > 0) {
        width = (int)Math.round(height * ratio);
      }
  
      // return virtual rendition
      if (width > 0 && height > 0) {
        if (rendition instanceof VirtualTransformedRenditionMetadata) {
          VirtualTransformedRenditionMetadata cropRendition = (VirtualTransformedRenditionMetadata)rendition;
          return new VirtualTransformedRenditionMetadata(cropRendition.getRendition(), width, height,
              cropRendition.getCropDimension(), cropRendition.getRotation());
        }
        else {
          return new VirtualRenditionMetadata(rendition.getRendition(), width, height);
        }
      }
      else {
        return null;
      }
    }
docs: Get virtual rendition for given width/height/ratio.
  @param rendition Rendition
  @param widthValue Width
  @param heightValue Height
  @param ratioValue Ratio
  @return Rendition or null