Liferay 6.2-ce-ga5

com.liferay.portal.kernel.image
Class ImageToolUtil

java.lang.Object
  extended by com.liferay.portal.kernel.image.ImageToolUtil

public class ImageToolUtil
extends Object

The Image utility class.


Constructor Summary
ImageToolUtil()
           
 
Method Summary
static Future<RenderedImage> convertCMYKtoRGB(byte[] bytes, String type)
          Returns the CMYK image converted to RGB using ImageMagick.
static BufferedImage convertImageType(BufferedImage sourceImage, int type)
          Returns the image converted to the type.
static void encodeGIF(RenderedImage renderedImage, OutputStream os)
          Encodes the image using the GIF format.
static void encodeWBMP(RenderedImage renderedImage, OutputStream os)
          Encodes the image using the WBMP format.
static BufferedImage getBufferedImage(RenderedImage renderedImage)
          Returns the rendered image as a BufferedImage.
static byte[] getBytes(RenderedImage renderedImage, String contentType)
          Returns the image as a byte[].
static Image getDefaultCompanyLogo()
           
static Image getDefaultOrganizationLogo()
           
static Image getDefaultSpacer()
           
static Image getDefaultUserFemalePortrait()
           
static Image getDefaultUserMalePortrait()
           
static Image getImage(byte[] bytes)
           
static Image getImage(File file)
           
static Image getImage(InputStream is)
           
static Image getImage(InputStream is, boolean cleanUpStream)
           
static ImageTool getImageTool()
           
static boolean isNullOrDefaultSpacer(byte[] bytes)
           
static ImageBag read(byte[] bytes)
          Detects the image format and creates an ImageBag containing the RenderedImage and image type.
static ImageBag read(File file)
          Detects the image format and creates an ImageBag containing the RenderedImage and image type.
static ImageBag read(InputStream inputStream)
           
static RenderedImage scale(RenderedImage renderedImage, int width)
          Returns the scaled image based on the given width with the height calculated to preserve aspect ratio.
static RenderedImage scale(RenderedImage renderedImage, int maxHeight, int maxWidth)
          Returns the scaled image based on the maximum height and width given while preserving the aspect ratio.
 void setImageTool(ImageTool imageTool)
           
static void write(RenderedImage renderedImage, String contentType, OutputStream os)
          Encodes the image using the content or image type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImageToolUtil

public ImageToolUtil()
Method Detail

convertCMYKtoRGB

public static Future<RenderedImage> convertCMYKtoRGB(byte[] bytes,
                                                     String type)
Returns the CMYK image converted to RGB using ImageMagick. This must be run against the original byte[] and not one extracted from a RenderedImage. The latter may potentially have been already been read incorrectly.

Parameters:
bytes - the image to convert
type - the image type (e.g., "gif", "jpg", etc.)
Returns:
the asynchronous process converting the image or 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.

convertImageType

public static BufferedImage convertImageType(BufferedImage sourceImage,
                                             int type)
Returns the image converted to the type.

Parameters:
sourceImage - the image to convert
type - the image type to convert to (e.g., "gif", "jpg", etc.)
Returns:
the converted image

encodeGIF

public static void encodeGIF(RenderedImage renderedImage,
                             OutputStream os)
                      throws IOException
Encodes the image using the GIF format.

Parameters:
renderedImage - the image to encode
os - the stream to write to
Throws:
IOException - if an IO exception occurred

encodeWBMP

public static void encodeWBMP(RenderedImage renderedImage,
                              OutputStream os)
                       throws IOException
Encodes the image using the WBMP format.

Parameters:
renderedImage - the image to encode
os - the stream to write to
Throws:
IOException - if an IO exception occurred

getBufferedImage

public static BufferedImage getBufferedImage(RenderedImage renderedImage)
Returns the rendered image as a BufferedImage.

Parameters:
renderedImage - the original image
Returns:
the converted image

getBytes

public static byte[] getBytes(RenderedImage renderedImage,
                              String contentType)
                       throws IOException
Returns the image as a byte[].

Parameters:
renderedImage - the image to read
contentType - the content type (e.g., "image/jpeg") or image type (e.g., "jpg") to use during encoding
Returns:
the encoded image
Throws:
IOException - if an IO exception occurred

getDefaultCompanyLogo

public static Image getDefaultCompanyLogo()

getDefaultOrganizationLogo

public static Image getDefaultOrganizationLogo()

getDefaultSpacer

public static Image getDefaultSpacer()

getDefaultUserFemalePortrait

public static Image getDefaultUserFemalePortrait()

getDefaultUserMalePortrait

public static Image getDefaultUserMalePortrait()

getImage

public static Image getImage(byte[] bytes)
                      throws IOException
Throws:
IOException

getImage

public static Image getImage(File file)
                      throws IOException
Throws:
IOException

getImage

public static Image getImage(InputStream is)
                      throws IOException
Throws:
IOException

getImage

public static Image getImage(InputStream is,
                             boolean cleanUpStream)
                      throws IOException
Throws:
IOException

getImageTool

public static ImageTool getImageTool()

isNullOrDefaultSpacer

public static boolean isNullOrDefaultSpacer(byte[] bytes)

read

public static ImageBag read(byte[] bytes)
                     throws IOException
Detects the image format and creates an ImageBag containing the RenderedImage and image type.

Parameters:
bytes - the bytes to read
Returns:
the ImageBag
Throws:
IOException - if an IO exception occurred

read

public static ImageBag read(File file)
                     throws IOException
Detects the image format and creates an ImageBag containing the RenderedImage and image type.

Parameters:
file - the file to read
Returns:
the ImageBag
Throws:
IOException - if an IO exception occurred

read

public static ImageBag read(InputStream inputStream)
                     throws IOException
Throws:
IOException

scale

public static RenderedImage scale(RenderedImage renderedImage,
                                  int width)
Returns the scaled image based on the given width with the height calculated to preserve aspect ratio.

Parameters:
renderedImage - the image to scale
width - the new width; also used to calculate the new height
Returns:
the scaled image

scale

public static RenderedImage scale(RenderedImage renderedImage,
                                  int maxHeight,
                                  int maxWidth)
Returns the scaled image based on the maximum height and width given while preserving the aspect ratio. If the image is already larger in both dimensions, the image will not be scaled.

Parameters:
renderedImage - the image to scale
maxHeight - the maximum height allowed for image
maxWidth - the maximum width allowed for image
Returns:
the scaled image

write

public static void write(RenderedImage renderedImage,
                         String contentType,
                         OutputStream os)
                  throws IOException
Encodes the image using the content or image type.

Parameters:
renderedImage - the image to encode
contentType - the content type (e.g., "image/jpeg") or image type (e.g., "jpg") to use during encoding
os - the stream to write to
Throws:
IOException - if an IO exception occurred

setImageTool

public void setImageTool(ImageTool imageTool)

Liferay 6.2-ce-ga5