com.gif4j
Class GifTransformer

java.lang.Object
  extended bycom.gif4j.GifTransformer

public class GifTransformer
extends java.lang.Object

Helper java class containing static methods to affine transform animated and non-animated GIF images represented by GifImage objects including resize, scale, rotate and flip gif image transform operations.

Resize GIF image using Java and GifTransformer

 // resize gif image to the width=150px with maintaining the aspect ratio of the original gif image dimension
 GifImage resizedGifImage1 = GifTransformer.resize(gifImage, 150, -1, false);
 // resize gif image to the width=150px and height=100px
 GifImage resizedGifImage2 = GifTransformer.resize(gifImage, 150, 100, false);
 

Scale GIF image using Java and GifTransformer

 // scale gif image by factor 0.5 with maintaining the aspect ratio of the original gif image dimension
 GifImage scaledGifImage1 = GifTransformer.scale(gifImage, 0.5, -1, false);
 // scale gif image by X-axis scale factor = 0.8 and Y-axis scale factor = 0.6
 GifImage scaledGifImage2 = GifTransformer.scale(gifImage, 0.8, 0.6, false);
 

Rotate GIF image using Java and GifTransformer

 // rotate gif image by 45 degrees (PI/4 radians)
 GifImage rotatedGifImage45 = GifTransformer.rotate(gifImage, Math.PI/4, false);
 // rotate gif image by 90 degrees counter-clockwise
 GifImage rotatedGifImage90CCW = GifTransformer.rotate90Left(gifImage);
 // rotate gif image by 90 degrees clockwise
 GifImage rotatedGifImage90CW = GifTransformer.rotate90Right(gifImage);
 // rotate gif image by 180 degrees
 GifImage rotatedGifImage180 = GifTransformer.rotate180(gifImage);
 

Flip and mirror GIF image using Java and GifTransformer

 // flip gif image vertical
 GifImage flipVerticalGifImage = GifTransformer.flipVertical(gifImage);
 // flip gif image horizontal (mirror gif image)
 GifImage flipHorizontalGifImage = GifTransformer.flipHorizontal(gifImage);
 

Since:
2.0
Version:
2.3
Author:
Gif4J Software - Java GIF image processing solutions
See Also:
GifImage, Quantizer

Method Summary
static GifImage crop(GifImage gifImage, java.awt.Rectangle cropArea)
          Create a cropped version of the specified gif image according to the specified rectangular area.
static GifImage exactRequantize(GifImage source, int quantizerMode, int colorsNum)
          Requantize frames of the GIF image using the specified quantizer mode to the specified number of colors.
static GifImage flipHorizontal(GifImage gifImage)
          Create a horizontally flip version of the specified gif image: mirror the specified gif image.
static GifImage flipVertical(GifImage gifImage)
          Create a vertically flip version of the specified gif image: the top row becomes the bottom row and vice versa, and so on.
static GifImage optimize(GifImage gifImage)
           
static GifImage requantize(GifImage source, int quantizerMode, int colorBitDepth)
          Requantize frames of the GIF image using the specified quantizer mode to the specified color bits depth.
static GifImage resize(GifImage gifImage, int width, int height, boolean smooth)
          Create a resized version of the specified gif image.
static GifImage resizeViaIR4J(GifImage gifImage, int width, int height, int interpolationType)
          Create a resized version of the specified gif image using ImageResize4J library.
static GifImage resizeViaIR4J(GifImage gifImage, int width, int height, int interpolationType, int colorBitDepth)
          Create a resized version of the specified gif image using ImageResize4J library.
static GifImage rotate(GifImage gifImage, double theta, boolean smooth)
          Create a rotated version of the specified gif image by the specified angle in radians.
static GifImage rotate180(GifImage gifImage)
          Create a rotated version of the specified gif image by 180 degrees
static GifImage rotate90Left(GifImage gifImage)
          Create a rotated version of the specified gif image by 90 degrees counter-clockwise (to the left).
static GifImage rotate90Right(GifImage gifImage)
          Create a rotated version of the specified gif image by 90 degrees clockwise (to the right).
static GifImage scale(GifImage gifImage, double xscale, double yscale, boolean smooth)
          Create a scaled version of the specified gif image.
static GifImage scaleViaIR4J(GifImage gifImage, double xscale, double yscale, int interpolationType)
          Create a scaled version of the specified gif image using ImageResize4J library.
static GifImage scaleViaIR4J(GifImage gifImage, double xscale, double yscale, int interpolationType, int colorBitDepth)
          Create a scaled version of the specified gif image using ImageResize4J library.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

crop

public static final GifImage crop(GifImage gifImage,
                                  java.awt.Rectangle cropArea)
Create a cropped version of the specified gif image according to the specified rectangular area.

Parameters:
gifImage - GifImage to crop
cropArea - crop area bounds
Returns:
a cropped version of the gif image
Throws:
java.lang.NullPointerException - If the specified GifImage is null
Since:
2.1
See Also:
GifImage

exactRequantize

public static final GifImage exactRequantize(GifImage source,
                                             int quantizerMode,
                                             int colorsNum)
Requantize frames of the GIF image using the specified quantizer mode to the specified number of colors.

Parameters:
quantizerMode - one of the predefined quantizer modes: ExactQuantizer.MEMORY_LOW_FAST, ExactQuantizer.MEMORY_LOW_FAST_DITHER, ExactQuantizer.MEMORY_LOW_OPTIMIZED, ExactQuantizer.MEMORY_LOW_OPTIMIZED_DITHER, ExactQuantizer.MEMORY_NORMAL_FAST, ExactQuantizer.MEMORY_NORMAL_FAST_DITHER, ExactQuantizer.MEMORY_NORMAL_OPTIMIZED, ExactQuantizer.MEMORY_NORMAL_OPTIMIZED_DITHER
source - the specified image to quantize
colorsNum - desired number of colors. Should be between 4 and 65536.
Returns:
requantized instance of GifImage
Throws:
java.lang.IllegalArgumentException - If desired number of colors less than 4 or more than 65536;
java.lang.IllegalArgumentException - If unknown quantizer mode;
java.lang.NullPointerException - If source image is null
Since:
2.3

flipHorizontal

public static final GifImage flipHorizontal(GifImage gifImage)
Create a horizontally flip version of the specified gif image: mirror the specified gif image.

Parameters:
gifImage - GifImage to flip
Returns:
a flip version of the gif image
Throws:
java.lang.NullPointerException - If the specified GifImage is null
Since:
2.0
See Also:
GifImage

flipVertical

public static final GifImage flipVertical(GifImage gifImage)
Create a vertically flip version of the specified gif image: the top row becomes the bottom row and vice versa, and so on.

Parameters:
gifImage - GifImage to flip
Returns:
a flip version of the gif image
Throws:
java.lang.NullPointerException - If the specified GifImage is null
Since:
2.0
See Also:
GifImage

optimize

public static final GifImage optimize(GifImage gifImage)

requantize

public static final GifImage requantize(GifImage source,
                                        int quantizerMode,
                                        int colorBitDepth)
Requantize frames of the GIF image using the specified quantizer mode to the specified color bits depth.

Parameters:
quantizerMode - one of the predefined quantizer modes: Quantizer.MEMORY_LOW_FAST, Quantizer.MEMORY_LOW_OPTIMIZED, Quantizer.MEMORY_LOW_OPTIMIZED_DITHER, Quantizer.MEMORY_NORMAL_FAST, Quantizer.MEMORY_NORMAL_FAST_DITHER, Quantizer.MEMORY_NORMAL_OPTIMIZED, Quantizer.MEMORY_NORMAL_OPTIMIZED_DITHER
source - the specified image to quantize
colorBitDepth - desired color table bit depth. Should be between 2 and 8.
Returns:
quantized instance of BufferedImage
Throws:
java.lang.IllegalArgumentException - If desired number of colors less than 2 or more than 8;
java.lang.IllegalArgumentException - If unknown quantizer mode;
java.lang.NullPointerException - If source image is null
Since:
2.3

resize

public static final GifImage resize(GifImage gifImage,
                                    int width,
                                    int height,
                                    boolean smooth)
Create a resized version of the specified gif image. A new GifImage object is returned which will render the GifImage at the specified width and height by default. If either the width or height is a negative number then a value is substituted to maintain the aspect ratio of the original gif image dimensions.

Parameters:
gifImage - GifImage to resize
width - the width to which to scale the GifImage
height - the height to which to scale the GifImage
smooth - choose a gif image resizing algorithm. If true then the gif image resizing algorithm that gives higher priority to GifImage smoothness than scaling speed is used.
Returns:
a resized version of the gif image
Throws:
java.lang.NullPointerException - If the specified GifImage is null
java.lang.NullPointerException - If the specified width and height are both less than or equal to 0
Since:
2.0
See Also:
GifImage

resizeViaIR4J

public static final GifImage resizeViaIR4J(GifImage gifImage,
                                           int width,
                                           int height,
                                           int interpolationType)
Create a resized version of the specified gif image using ImageResize4J library.

Note: You should have ImageResize4J library jar in CLASSPATH!

A new GifImage object is returned which will render the GifImage at the specified width and height by default. If either the width or height is a negative number then a value is substituted to maintain the aspect ratio of the original gif image dimensions.

Parameters:
gifImage - GifImage to resize
width - the width to which to scale the GifImage
height - the height to which to scale the GifImage
interpolationType - one of the integer interpolation type constants defined in com.imageresize4j.ImageResizeProcessor class.
Returns:
a resized version of the gif image
Throws:
java.lang.NullPointerException - If the specified GifImage is null
java.lang.NullPointerException - If the specified width and height are both less than or equal to 0
java.lang.RuntimeException - If com.imageresize4j.ImageResizeProcessor not found in CLASSPATH.
Since:
2.2
See Also:
GifImage

resizeViaIR4J

public static final GifImage resizeViaIR4J(GifImage gifImage,
                                           int width,
                                           int height,
                                           int interpolationType,
                                           int colorBitDepth)
Create a resized version of the specified gif image using ImageResize4J library.

Note: You should have ImageResize4J library jar in CLASSPATH!

A new GifImage object is returned which will render the GifImage at the specified width and height by default. If either the width or height is a negative number then a value is substituted to maintain the aspect ratio of the original gif image dimensions.

Parameters:
gifImage - GifImage to resize
width - the width to which to scale the GifImage
height - the height to which to scale the GifImage
interpolationType - one of the integer interpolation type constants defined in com.imageresize4j.ImageResizeProcessor class.
colorBitDepth - desired color table bit depth of scaled image. Should be between 2 and 16. To determine actual size of the color table, raise 2 to this parameter: for example, to quantize the specified image to 256 colors this parameter has to be equal to 8 (raise 2 to 8 = 256).
Returns:
a resized version of the gif image
Throws:
java.lang.NullPointerException - If the specified GifImage is null
java.lang.NullPointerException - If the specified width and height are both less than or equal to 0
java.lang.RuntimeException - If com.imageresize4j.ImageResizeProcessor not found in CLASSPATH.
Since:
2.2
See Also:
GifImage

rotate

public static final GifImage rotate(GifImage gifImage,
                                    double theta,
                                    boolean smooth)
Create a rotated version of the specified gif image by the specified angle in radians.

Parameters:
gifImage - GifImage to rotate
theta - the angle of rotation in radians
smooth - choose a gif image rotating algorithm. If true then the gif image rotating algorithm that gives higher priority to GifImage smoothness than rotating speed is used.
Returns:
a rotated version of the gif image
Since:
2.0
See Also:
GifImage

rotate180

public static final GifImage rotate180(GifImage gifImage)
Create a rotated version of the specified gif image by 180 degrees

Parameters:
gifImage - GifImage to rotate
Returns:
a rotated version of the gif image
Throws:
java.lang.NullPointerException - If the specified GifImage is null
Since:
2.0
See Also:
GifImage

rotate90Left

public static final GifImage rotate90Left(GifImage gifImage)
Create a rotated version of the specified gif image by 90 degrees counter-clockwise (to the left).

Parameters:
gifImage - GifImage to rotate
Returns:
a rotated version of the gif image
Throws:
java.lang.NullPointerException - If the specified GifImage is null
Since:
2.0
See Also:
GifImage

rotate90Right

public static final GifImage rotate90Right(GifImage gifImage)
Create a rotated version of the specified gif image by 90 degrees clockwise (to the right).

Parameters:
gifImage - GifImage to rotate
Returns:
a rotated version of the gif image
Throws:
java.lang.NullPointerException - If the specified GifImage is null
Since:
2.0
See Also:
GifImage

scale

public static final GifImage scale(GifImage gifImage,
                                   double xscale,
                                   double yscale,
                                   boolean smooth)
Create a scaled version of the specified gif image. A new GifImage object is returned which will render the GifImage at the calculated width and height by default. If either the xscale or yscale is a negative number then a value is substituted to maintain the aspect ratio of the original gif image dimensions.

Parameters:
gifImage - GifImage to resize
xscale - the factor by which GifImage are scaled along the X axis direction
yscale - the factor by which GifImage are scaled along the Y axis direction
smooth - choose a gif image scaling algorithm. If true then the gif image scaling algorithm that gives higher priority to GifImage smoothness than scaling speed is used.
Returns:
a scaled version of the gif image
Throws:
java.lang.NullPointerException - If the specified GifImage is null
java.lang.NullPointerException - If the specified xscale and yscale are both less than or equal to 0
Since:
2.0
See Also:
GifImage

scaleViaIR4J

public static final GifImage scaleViaIR4J(GifImage gifImage,
                                          double xscale,
                                          double yscale,
                                          int interpolationType)
Create a scaled version of the specified gif image using ImageResize4J library.

Note: You should have ImageResize4J library jar in CLASSPATH!

A new GifImage object is returned which will render the GifImage at the calculated width and height by default. If either the xscale or yscale is a negative number then a value is substituted to maintain the aspect ratio of the original gif image dimensions.

Parameters:
gifImage - GifImage to resize
xscale - the factor by which GifImage are scaled along the X axis direction
yscale - the factor by which GifImage are scaled along the Y axis direction
interpolationType - one of the integer interpolation type constants defined in com.imageresize4j.ImageResizeProcessor class.
Returns:
a scaled version of the gif image
Throws:
java.lang.NullPointerException - If the specified GifImage is null
java.lang.NullPointerException - If the specified xscale and yscale are both less than or equal to 0
java.lang.RuntimeException - If com.imageresize4j.ImageResizeProcessor not found in CLASSPATH.
Since:
2.2
See Also:
GifImage

scaleViaIR4J

public static final GifImage scaleViaIR4J(GifImage gifImage,
                                          double xscale,
                                          double yscale,
                                          int interpolationType,
                                          int colorBitDepth)
Create a scaled version of the specified gif image using ImageResize4J library.

Note: You should have ImageResize4J library jar in CLASSPATH!

A new GifImage object is returned which will render the GifImage at the calculated width and height by default. If either the xscale or yscale is a negative number then a value is substituted to maintain the aspect ratio of the original gif image dimensions.

Parameters:
gifImage - GifImage to resize
xscale - the factor by which GifImage are scaled along the X axis direction
yscale - the factor by which GifImage are scaled along the Y axis direction
interpolationType - one of the integer interpolation type constants defined in com.imageresize4j.ImageResizeProcessor class.
colorBitDepth - desired color table bit depth of scaled image. Should be between 2 and 16. To determine actual size of the color table, raise 2 to this parameter: for example, to quantize the specified image to 256 colors this parameter has to be equal to 8 (raise 2 to 8 = 256).
Returns:
a scaled version of the gif image
Throws:
java.lang.NullPointerException - If the specified GifImage is null
java.lang.NullPointerException - If the specified xscale and yscale are both less than or equal to 0
java.lang.RuntimeException - If com.imageresize4j.ImageResizeProcessor not found in CLASSPATH.
Since:
2.2
See Also:
GifImage