Package org.cyclos.server.utils
Class ServerImageHelper
- java.lang.Object
-
- org.cyclos.server.utils.ServerImageHelper
-
public class ServerImageHelper extends Object
Helper class for working with images
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classServerImageHelper.ImageTypeContains the known image types
-
Field Summary
Fields Modifier and Type Field Description static org.apache.commons.io.filefilter.IOFileFilterFILE_CONTENT_FILTERA file filter which opens each file, accepting those whose content represent an image
-
Constructor Summary
Constructors Constructor Description ServerImageHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static DimensiongetActualSize(Dimension original, Integer requestedWidth, Integer requestedHeight)Return the size according to the original size and the optional requested dimensionsstatic StringgetConfigurationImageUrl(RequestData requestData, ConfigurationImageVO image, String resourceCacheKey)Returns the URL for a configuration imagestatic BufferedImagegradient(int width, int height, Color[] colors)Generates an image containing a gradient which passes through the given colors distributed evenly through the heightstatic BufferedImagegradient(int width, int height, Color[] colors, float[] points)Generates an image containing a gradient which passes through the given colors at the given pointsstatic URIimageURI(ImageVO vo, RequestData requestData, String resourceCacheKey)static DimensionrescaleKeepingProportions(Dimension originalSize, Dimension desiredSize, Dimension maxSize)Calculates the rescaled image size for the given original and desired sizes.static BufferedImageresize(BufferedImage bufferedImage, int width, int height)Resizes the given imagestatic BufferedImageresize(BufferedImage originalImage, Dimension maxSize)Resizes the image respecting the maximum thumbnail sizestatic DimensionthumbnailSize(Dimension originalSize, Dimension maxSize)Calculates the thumbnail size for the given original and maximum sizesstatic byte[]toBytes(BufferedImage image, ServerImageHelper.ImageType type, int quality)Returns the given image bytes, encoded with the given typestatic StringtoLogoKind(ConfigurationImageType type)Return the value representing the LogoKind in REST.static StringtoThemeImageKind(ThemeImageType type)Return the value representing the ThemeImageKind in REST.static voidwrite(BufferedImage image, ServerImageHelper.ImageType type, File file, int jpegQuality)Write the given image as the given format to the given filestatic voidwrite(BufferedImage image, ServerImageHelper.ImageType type, OutputStream out, int quality)Write the given image as the given format to the given output stream
-
-
-
Method Detail
-
getActualSize
public static Dimension getActualSize(Dimension original, Integer requestedWidth, Integer requestedHeight)
Return the size according to the original size and the optional requested dimensions
-
getConfigurationImageUrl
public static String getConfigurationImageUrl(RequestData requestData, ConfigurationImageVO image, String resourceCacheKey)
Returns the URL for a configuration image
-
gradient
public static BufferedImage gradient(int width, int height, Color[] colors)
Generates an image containing a gradient which passes through the given colors distributed evenly through the height
-
gradient
public static BufferedImage gradient(int width, int height, Color[] colors, float[] points)
Generates an image containing a gradient which passes through the given colors at the given points
-
imageURI
public static URI imageURI(ImageVO vo, RequestData requestData, String resourceCacheKey)
-
rescaleKeepingProportions
public static Dimension rescaleKeepingProportions(Dimension originalSize, Dimension desiredSize, @Nullable Dimension maxSize)
Calculates the rescaled image size for the given original and desired sizes. Also makes sure the desired size is never larger than the given maxSize.
-
resize
public static BufferedImage resize(BufferedImage originalImage, Dimension maxSize)
Resizes the image respecting the maximum thumbnail size
-
resize
public static BufferedImage resize(BufferedImage bufferedImage, int width, int height)
Resizes the given image
-
thumbnailSize
public static Dimension thumbnailSize(Dimension originalSize, Dimension maxSize)
Calculates the thumbnail size for the given original and maximum sizes
-
toBytes
public static byte[] toBytes(BufferedImage image, ServerImageHelper.ImageType type, int quality)
Returns the given image bytes, encoded with the given type
-
toLogoKind
public static String toLogoKind(ConfigurationImageType type)
Return the value representing the LogoKind in REST.
-
toThemeImageKind
public static String toThemeImageKind(ThemeImageType type)
Return the value representing the ThemeImageKind in REST.
-
write
public static void write(BufferedImage image, ServerImageHelper.ImageType type, File file, int jpegQuality) throws IOException
Write the given image as the given format to the given file- Throws:
IOException
-
write
public static void write(BufferedImage image, ServerImageHelper.ImageType type, OutputStream out, int quality) throws IOException
Write the given image as the given format to the given output stream- Throws:
IOException
-
-