Class ImageUtil
- java.lang.Object
-
- org.xwiki.rendering.wikimodel.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).- Since:
- 4.0M1
- Version:
- $Id: 2b0c0e29d583c58caa42a22a0353693cbb8f7e3f $
-
-
Constructor Summary
Constructors Constructor Description ImageUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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.
-
-
-
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 reduceoutput
- the output stream where the resulting reduced image is writtenthumbWidth
- the maximal width of the reduced imagethumbHeight
- the maximal height of the reduced imageformat
- 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 imagemaxWidth
- the maximal widthmaxHeight
- 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 imageheight
- the initial height of an imagemaxWidth
- the maximal width of an imagemaxHeight
- 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
-
-