public class FitTo extends ScaleCalculator
Scales an image to approximately similar in size to a SizeXY.

Optionally, the aspect-ratio is preserved between width and height.

Optionally, the eventual width, and height can be rounded to the nearest whole multiple of an integer.

Author:
Owen Feehan
  • Constructor Details

    • FitTo

      public FitTo()
  • Method Details

    • calculate

      public ScaleFactor calculate(Optional<Dimensions> dimensionsToBeScaled, Optional<ImageSizeSuggestion> suggestedSize) throws OperationFailedException
      Description copied from class: ScaleCalculator
      Calculates a scaling-factor for a source image/entity of particular dimensions.
      Specified by:
      calculate in class ScaleCalculator
      Parameters:
      dimensionsToBeScaled - dimensions of the source image/entity that will be scaled, if they are known.
      suggestedSize - a string suggesting dimensions to resize to or a scaling-factor.
      Returns:
      the scaling-factor to use.
      Throws:
      OperationFailedException - if a scale-factor cannot be successfully calculated.
    • getTargetSize

      public SizeXY getTargetSize()
      The target size. The image will be scaled to be as similar to this as possible, preserving aspect ratio.
    • setTargetSize

      public void setTargetSize(SizeXY targetSize)
      The target size. The image will be scaled to be as similar to this as possible, preserving aspect ratio.
    • isPreserveAspectRatio

      public boolean isPreserveAspectRatio()
      If true, the aspect-ratio is preserved between width and height. Otherwise, they are treated independently.
    • setPreserveAspectRatio

      public void setPreserveAspectRatio(boolean preserveAspectRatio)
      If true, the aspect-ratio is preserved between width and height. Otherwise, they are treated independently.
    • getMultipleOf

      public int getMultipleOf()
      The eventual width and height of the image must be a multiple of this number. Effecitvely disabled when == 1
    • setMultipleOf

      public void setMultipleOf(int multipleOf)
      The eventual width and height of the image must be a multiple of this number. Effecitvely disabled when == 1