Class ImageTransformerScaleToArea

java.lang.Object
one.jpro.platform.image.manager.transformer.ImageTransformerScaleToArea
All Implemented Interfaces:
JsonConvertible, ImageTransformer

public class ImageTransformerScaleToArea extends Object implements ImageTransformer
This class implements an image transformer that scales images to a target area while preserving the original aspect ratio.
See Also:
  • Constructor Details

    • ImageTransformerScaleToArea

      public ImageTransformerScaleToArea(int targetArea)
      Constructs an instance with the specified target area.
      Parameters:
      targetArea - The desired area (in pixels) of the scaled image.
      Throws:
      IllegalArgumentException - if targetArea is not positive.
    • ImageTransformerScaleToArea

      public ImageTransformerScaleToArea(int targetWidth, int targetHeight)
      Constructs an instance with a specified target width and height. The target area will be calculated as the product of targetWidth and targetHeight.
      Parameters:
      targetWidth - The desired width of the scaled image.
      targetHeight - The desired height of the scaled image.
  • Method Details

    • transform

      public BufferedImage transform(BufferedImage image)
      Transforms the given image, scaling it to the desired area while maintaining its original aspect ratio.
      Specified by:
      transform in interface ImageTransformer
      Parameters:
      image - The original image to be transformed.
      Returns:
      The scaled image with the target area.
    • toJSON

      public org.json.JSONObject toJSON()
      Description copied from interface: JsonConvertible
      Converts the object to a JSON representation.
      Specified by:
      toJSON in interface JsonConvertible
      Returns:
      A JSONObject representing the object.