public class ImageToolUtil
extends java.lang.Object
| Constructor and Description |
|---|
ImageToolUtil() |
| Modifier and Type | Method and Description |
|---|---|
static java.util.concurrent.Future<java.awt.image.RenderedImage> |
convertCMYKtoRGB(byte[] bytes,
java.lang.String type)
Returns the CMYK image converted to RGB using ImageMagick.
|
static java.awt.image.BufferedImage |
convertImageType(java.awt.image.BufferedImage sourceImage,
int type)
Returns the image converted to the type.
|
static java.awt.image.RenderedImage |
crop(java.awt.image.RenderedImage renderedImage,
int height,
int width,
int x,
int y) |
static void |
encodeGIF(java.awt.image.RenderedImage renderedImage,
java.io.OutputStream outputStream)
Encodes the image using the GIF format.
|
static void |
encodeWBMP(java.awt.image.RenderedImage renderedImage,
java.io.OutputStream outputStream)
Encodes the image using the WBMP format.
|
static java.awt.image.RenderedImage |
flipHorizontal(java.awt.image.RenderedImage renderedImage) |
static java.awt.image.RenderedImage |
flipVertical(java.awt.image.RenderedImage renderedImage) |
static java.awt.image.BufferedImage |
getBufferedImage(java.awt.image.RenderedImage renderedImage)
Returns the rendered image as a
BufferedImage. |
static byte[] |
getBytes(java.awt.image.RenderedImage renderedImage,
java.lang.String contentType)
Returns the image as a
byte[]. |
static com.liferay.portal.kernel.model.Image |
getDefaultCompanyLogo() |
static com.liferay.portal.kernel.model.Image |
getDefaultOrganizationLogo() |
static com.liferay.portal.kernel.model.Image |
getDefaultSpacer() |
static com.liferay.portal.kernel.model.Image |
getDefaultUserFemalePortrait() |
static com.liferay.portal.kernel.model.Image |
getDefaultUserMalePortrait() |
static com.liferay.portal.kernel.model.Image |
getDefaultUserPortrait() |
static com.liferay.portal.kernel.model.Image |
getImage(byte[] bytes) |
static com.liferay.portal.kernel.model.Image |
getImage(java.io.File file) |
static com.liferay.portal.kernel.model.Image |
getImage(java.io.InputStream inputStream) |
static com.liferay.portal.kernel.model.Image |
getImage(java.io.InputStream inputStream,
boolean cleanUpStream) |
static boolean |
isNullOrDefaultSpacer(byte[] bytes) |
static com.liferay.portal.kernel.image.ImageBag |
read(byte[] bytes)
Detects the image format and creates an
ImageBag containing the
RenderedImage and image type. |
static com.liferay.portal.kernel.image.ImageBag |
read(java.io.File file)
Detects the image format and creates an
ImageBag containing the
RenderedImage and image type. |
static com.liferay.portal.kernel.image.ImageBag |
read(java.io.InputStream inputStream) |
static java.awt.image.RenderedImage |
rotate(java.awt.image.RenderedImage renderedImage,
int degrees) |
static java.awt.image.RenderedImage |
scale(java.awt.image.RenderedImage renderedImage,
int width)
Returns the scaled image based on the given width with the height
calculated to preserve aspect ratio.
|
static java.awt.image.RenderedImage |
scale(java.awt.image.RenderedImage renderedImage,
int maxHeight,
int maxWidth)
Returns the scaled image based on the maximum height and width given
while preserving the aspect ratio.
|
static void |
write(java.awt.image.RenderedImage renderedImage,
java.lang.String contentType,
java.io.OutputStream outputStream)
Encodes the image using the content or image type.
|
public static java.util.concurrent.Future<java.awt.image.RenderedImage> convertCMYKtoRGB(byte[] bytes,
java.lang.String type)
byte[] and not one extracted from a
RenderedImage. The latter may potentially have been already been
read incorrectly.bytes - the image to converttype - the image type (e.g., "gif", "jpg", etc.)null
if ImageMagick was disabled or if the conversion could
not be completed. The conversion may not complete if (1) the
image was not in the CMYK colorspace to begin with or (2) there
was an error in the conversion process.public static java.awt.image.BufferedImage convertImageType(java.awt.image.BufferedImage sourceImage,
int type)
sourceImage - the image to converttype - the image type to convert to (e.g., "gif", "jpg", etc.)public static java.awt.image.RenderedImage crop(java.awt.image.RenderedImage renderedImage,
int height,
int width,
int x,
int y)
public static void encodeGIF(java.awt.image.RenderedImage renderedImage,
java.io.OutputStream outputStream)
throws java.io.IOException
renderedImage - the image to encodeoutputStream - the stream to write tojava.io.IOException - if an IO exception occurredpublic static void encodeWBMP(java.awt.image.RenderedImage renderedImage,
java.io.OutputStream outputStream)
throws java.io.IOException
renderedImage - the image to encodeoutputStream - the stream to write tojava.io.IOException - if an IO exception occurredpublic static java.awt.image.RenderedImage flipHorizontal(java.awt.image.RenderedImage renderedImage)
public static java.awt.image.RenderedImage flipVertical(java.awt.image.RenderedImage renderedImage)
public static java.awt.image.BufferedImage getBufferedImage(java.awt.image.RenderedImage renderedImage)
BufferedImage.renderedImage - the original imagepublic static byte[] getBytes(java.awt.image.RenderedImage renderedImage,
java.lang.String contentType)
throws java.io.IOException
byte[].renderedImage - the image to readcontentType - the content type (e.g., "image/jpeg") or image type
(e.g., "jpg") to use during encodingjava.io.IOException - if an IO exception occurredpublic static com.liferay.portal.kernel.model.Image getDefaultCompanyLogo()
public static com.liferay.portal.kernel.model.Image getDefaultOrganizationLogo()
public static com.liferay.portal.kernel.model.Image getDefaultSpacer()
public static com.liferay.portal.kernel.model.Image getDefaultUserFemalePortrait()
public static com.liferay.portal.kernel.model.Image getDefaultUserMalePortrait()
public static com.liferay.portal.kernel.model.Image getDefaultUserPortrait()
public static com.liferay.portal.kernel.model.Image getImage(byte[] bytes)
throws com.liferay.portal.kernel.exception.ImageResolutionException,
java.io.IOException
com.liferay.portal.kernel.exception.ImageResolutionExceptionjava.io.IOExceptionpublic static com.liferay.portal.kernel.model.Image getImage(java.io.File file)
throws com.liferay.portal.kernel.exception.ImageResolutionException,
java.io.IOException
com.liferay.portal.kernel.exception.ImageResolutionExceptionjava.io.IOExceptionpublic static com.liferay.portal.kernel.model.Image getImage(java.io.InputStream inputStream)
throws com.liferay.portal.kernel.exception.ImageResolutionException,
java.io.IOException
com.liferay.portal.kernel.exception.ImageResolutionExceptionjava.io.IOExceptionpublic static com.liferay.portal.kernel.model.Image getImage(java.io.InputStream inputStream,
boolean cleanUpStream)
throws com.liferay.portal.kernel.exception.ImageResolutionException,
java.io.IOException
com.liferay.portal.kernel.exception.ImageResolutionExceptionjava.io.IOExceptionpublic static boolean isNullOrDefaultSpacer(byte[] bytes)
public static com.liferay.portal.kernel.image.ImageBag read(byte[] bytes)
throws com.liferay.portal.kernel.exception.ImageResolutionException,
java.io.IOException
ImageBag containing the
RenderedImage and image type.bytes - the bytes to readImageBagcom.liferay.portal.kernel.exception.ImageResolutionException - if the image's dimensions were larger
than those specified by portal properties
image.tool.image.max.height and
image.tool.image.max.widthjava.io.IOException - if an IO exception occurredpublic static com.liferay.portal.kernel.image.ImageBag read(java.io.File file)
throws com.liferay.portal.kernel.exception.ImageResolutionException,
java.io.IOException
ImageBag containing the
RenderedImage and image type.file - the file to readImageBagcom.liferay.portal.kernel.exception.ImageResolutionException - if the image's dimensions were larger
than those specified by portal properties
image.tool.image.max.height and
image.tool.image.max.widthjava.io.IOException - if an IO exception occurredpublic static com.liferay.portal.kernel.image.ImageBag read(java.io.InputStream inputStream)
throws com.liferay.portal.kernel.exception.ImageResolutionException,
java.io.IOException
com.liferay.portal.kernel.exception.ImageResolutionExceptionjava.io.IOExceptionpublic static java.awt.image.RenderedImage rotate(java.awt.image.RenderedImage renderedImage,
int degrees)
public static java.awt.image.RenderedImage scale(java.awt.image.RenderedImage renderedImage,
int width)
renderedImage - the image to scalewidth - the new width; also used to calculate the new heightpublic static java.awt.image.RenderedImage scale(java.awt.image.RenderedImage renderedImage,
int maxHeight,
int maxWidth)
renderedImage - the image to scalemaxHeight - the maximum height allowed for imagemaxWidth - the maximum width allowed for imagepublic static void write(java.awt.image.RenderedImage renderedImage,
java.lang.String contentType,
java.io.OutputStream outputStream)
throws java.io.IOException
renderedImage - the image to encodecontentType - the content type (e.g., "image/jpeg") or image type
(e.g., "jpg") to use during encodingoutputStream - the stream to write tojava.io.IOException - if an IO exception occurred