Class ImageCompression


  • public final class ImageCompression
    extends Object
    Settings for compressing an uploaded image: the size it should be scaled down to, the format it should be converted to and the quality it should be stored with. The form designer lets users configure these settings for an upload element.
    Since:
    8.6.0
    Author:
    XIMA MEDIA GmbH
    • Constructor Detail

      • ImageCompression

        public ImageCompression​(Integer maxWidth,
                                Integer maxHeight,
                                String format,
                                Double quality)
        Creates new image compression settings.
        Parameters:
        maxWidth - Width the image should be scaled down to, or null or a value that is not positive when the width does not matter. The aspect ratio of the image is always kept, and images are never scaled up.
        maxHeight - Height the image should be scaled down to, or null or a value that is not positive when the height does not matter.
        format - Format the image should be converted to: FORMAT_JPEG or FORMAT_PNG, or FORMAT_AUTO (the default) to keep the format of the uploaded image.
        quality - Quality (between 0 and 100) the image should be stored with, for formats that compress with a loss of quality. Defaults to 85 when null.
        Since:
        8.6.0
    • Method Detail

      • forUploadElement

        public static ImageCompression forUploadElement​(XItem uploadElement)
        Reads the compression settings the given upload element of a form is configured with.
        Parameters:
        uploadElement - The upload element of the form the image was uploaded with.
        Returns:
        The compression to apply to the images uploaded with the given element, or null when the element is not configured to have its images compressed on the server.
        Since:
        8.6.0
      • getMaxHeight

        public int getMaxHeight()
        Returns:
        The height the image should be scaled down to, or 0 when the height does not matter.
        Since:
        8.6.0
      • getMaxWidth

        public int getMaxWidth()
        Returns:
        The width the image should be scaled down to, or 0 when the width does not matter.
        Since:
        8.6.0
      • getQuality

        public double getQuality()
        Returns:
        The quality (between 0 and 100) the image should be stored with, for formats that compress with a loss of quality.
        Since:
        8.6.0