code: private Dimension getImageDimension() {
      Dimension dimension = null;
  
      // check for cropping dimension
      if (this.media.getCropDimension() != null) {
        dimension = this.media.getCropDimension();
      }
      else {
        // if binary is image try to calculcate dimensions by loading it into a layer
        Layer layer = this.resource.adaptTo(Layer.class);
        if (layer != null) {
          dimension = new Dimension(layer.getWidth(), layer.getHeight());
        }
      }
  
      return dimension;
    }
docs: Gets the dimension of the uploaded image (if the binary is an image file at all).
  @return Dimension