Class ImageCompression
- java.lang.Object
-
- de.xima.fc.form.common.upload.image.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
-
-
Field Summary
Fields Modifier and Type Field Description static StringFORMAT_AUTOValue ofgetFormat()that means 'keep the format of the uploaded image'.static StringFORMAT_JPEGValue ofgetFormat()that means 'convert the uploaded image to JPEG'.static StringFORMAT_PNGValue ofgetFormat()that means 'convert the uploaded image to PNG'.
-
Constructor Summary
Constructors Constructor Description ImageCompression(Integer maxWidth, Integer maxHeight, String format, Double quality)Creates new image compression settings.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ImageCompressionforUploadElement(XItem uploadElement)Reads the compression settings the given upload element of a form is configured with.StringgetFormat()intgetMaxHeight()intgetMaxWidth()doublegetQuality()
-
-
-
Field Detail
-
FORMAT_AUTO
public static final String FORMAT_AUTO
Value ofgetFormat()that means 'keep the format of the uploaded image'.- See Also:
- Constant Field Values
-
FORMAT_JPEG
public static final String FORMAT_JPEG
Value ofgetFormat()that means 'convert the uploaded image to JPEG'.- See Also:
- Constant Field Values
-
FORMAT_PNG
public static final String FORMAT_PNG
Value ofgetFormat()that means 'convert the uploaded image to PNG'.- See Also:
- Constant Field Values
-
-
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, ornullor 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, ornullor a value that is not positive when the height does not matter.format- Format the image should be converted to:FORMAT_JPEGorFORMAT_PNG, orFORMAT_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 whennull.- 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
nullwhen the element is not configured to have its images compressed on the server. - Since:
- 8.6.0
-
getFormat
public String getFormat()
- Returns:
- The format the image should be converted to:
FORMAT_JPEG,FORMAT_PNGorFORMAT_AUTO, nevernull. - 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
-
-