org.varienaja.util.coverart
Class ImageScaler

java.lang.Object
  extended by org.varienaja.util.coverart.ImageScaler

public class ImageScaler
extends java.lang.Object

This class provides functions for scaling square jpeg-images to new sizes.

Author:
Varienaja

Constructor Summary
ImageScaler()
           
 
Method Summary
static java.awt.Dimension calculateNewDimension(int width, int height, int newSize)
          Calculates a new dimension for an object.
static java.awt.image.BufferedImage scale(java.awt.Image image, int newSize)
          Scales a source-image to a new image
static java.awt.image.BufferedImage scale(java.io.InputStream input, int newSize)
          Scales a source-jpeg to a new image
static boolean scale(java.io.InputStream input, java.lang.String dest, int newSize)
          Scales a source-jpeg to a new jpeg.
static boolean scale(java.lang.String source, java.lang.String dest, int newSize)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImageScaler

public ImageScaler()
Method Detail

scale

public static boolean scale(java.io.InputStream input,
                            java.lang.String dest,
                            int newSize)
Scales a source-jpeg to a new jpeg. The new jpeg will be compressed with a quality of 90%.

Parameters:
input - The source jpeg to use
dest - The filename of the target jpeg (will be generated)
newSize - The new size of the image (will be used for both x and y)
Returns:
true, if the resize operation succeeded, false otherwise

scale

public static boolean scale(java.lang.String source,
                            java.lang.String dest,
                            int newSize)
                     throws java.io.FileNotFoundException
Throws:
java.io.FileNotFoundException

scale

public static java.awt.image.BufferedImage scale(java.io.InputStream input,
                                                 int newSize)
                                          throws java.lang.Exception
Scales a source-jpeg to a new image

Parameters:
input - The source jpeg to use
newSize - The new size of the image (will be used for both x and y)
Returns:
The image as a BufferedImage
Throws:
java.lang.Exception

scale

public static java.awt.image.BufferedImage scale(java.awt.Image image,
                                                 int newSize)
                                          throws java.lang.Exception
Scales a source-image to a new image

Parameters:
image - The image to use as source
newSize - The new size of the image (will be used for both x and y)
Returns:
The image as a BufferedImage
Throws:
java.lang.Exception

calculateNewDimension

public static java.awt.Dimension calculateNewDimension(int width,
                                                       int height,
                                                       int newSize)
Calculates a new dimension for an object.

Parameters:
width - The width of an object.
height - The height of an object.
newSize - The maximum size of an object (both width and height)
Returns:
The new Dimension of the image, where width or height are exactly newSize and the aspect-ratio is unchanged.


Copyright © 2010 A.J.V.. All Rights Reserved.