code: public static void getImagePosition(Matrix matrix, Settings settings, Rect out) {
          tmpRectF.set(0, 0, settings.getImageW(), settings.getImageH());
  
          matrix.mapRect(tmpRectF);
  
          final int w = Math.round(tmpRectF.width());
          final int h = Math.round(tmpRectF.height());
  
          // Calculating image position basing on gravity
          tmpRect1.set(0, 0, settings.getViewportW(), settings.getViewportH());
          Gravity.apply(settings.getGravity(), w, h, tmpRect1, out);
      }
docs: Calculates image position (scaled and rotated) within viewport area with gravity applied.
  
  @param matrix Image matrix
  @param settings Image settings
  @param out Output rectangle