org.wikimodel.wem.images
Class ImageUtil

java.lang.Object
  extended by org.wikimodel.wem.images.ImageUtil

public class ImageUtil
extends Object

Contains utility methods dealing with images like image size definition or creation of thumbnails (reduced copies of images).

Author:
kotelnikov

Constructor Summary
ImageUtil()
           
 
Method Summary
static void createThumb(InputStream input, OutputStream output, int thumbWidth, int thumbHeight, String format)
          Create a reduced image (thumb) of an image from the given input stream.
static int[] getImageSize(InputStream input)
          Returns the size (width and height) of an image from the given input stream.
static int[] getImageSize(InputStream input, int maxWidth, int maxHeight)
          Returns the possible size of an image from the given input stream; the returned size does not overcome the specified maximal borders but keeps the ratio of the image.
static int[] getNewSize(int width, int height, int maxWidth, int maxHeight)
          Calculates new size of an image with the specified max borders keeping the ratio between height and width of the image.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImageUtil

public ImageUtil()
Method Detail

createThumb

public static void createThumb(InputStream input,
                               OutputStream output,
                               int thumbWidth,
                               int thumbHeight,
                               String format)
                        throws IOException
Create a reduced image (thumb) of an image from the given input stream. Possible output formats are "jpg" or "png" (no "gif"; it is possible to read "gif" files, but not to write). The resulting thumb is written to the output stream. The both streams will be explicitly closed by this method. This method keeps the ratio width/height of the initial image. If both dimensions of the initial image is less than the specified boundaries it is not re-scaled; it is written to the output stream as is.

Parameters:
input - the input stream containing the image to reduce
output - the output stream where the resulting reduced image is written
thumbWidth - the maximal width of the reduced image
thumbHeight - the maximal height of the reduced image
format - the output format of the reduced image; it can be "jpg", "png", ...
Throws:
IOException

getImageSize

public static int[] getImageSize(InputStream input)
                          throws IOException
Returns the size (width and height) of an image from the given input stream. This method closes the given stream.

Parameters:
input - the input stream with an image
Returns:
the size (width and height) of an image from the given input stream
Throws:
IOException

getImageSize

public static int[] getImageSize(InputStream input,
                                 int maxWidth,
                                 int maxHeight)
                          throws IOException
Returns the possible size of an image from the given input stream; the returned size does not overcome the specified maximal borders but keeps the ratio of the image. This method closes the given stream.

Parameters:
input - the input stream with an image
maxWidth - the maximal width
maxHeight - the maximal height
Returns:
the possible size of an image from the given input stream; the returned size does not overcome the specified maximal borders but keeps the ratio of the image
Throws:
IOException

getNewSize

public static int[] getNewSize(int width,
                               int height,
                               int maxWidth,
                               int maxHeight)
Calculates new size of an image with the specified max borders keeping the ratio between height and width of the image.

Parameters:
width - the initial width of an image
height - the initial height of an image
maxWidth - the maximal width of an image
maxHeight - the maximal height of an image
Returns:
a new size of an image where the height and width don't overcome the specified borders; the size keeps the initial image ratio between width and height


Copyright © 2005-2012. All Rights Reserved.