 |
Transform a GIF Image
The GifTransformer class
is the 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.
The next methods to transform gif images are available (please consult the Gif4J PRO Java API for more info):
public static final GifImage rotate(GifImage gifImage, double theta, boolean smooth);
public static final GifImage rotate90Left(GifImage gifImage);
public static final GifImage rotate90Right(GifImage gifImage);
public static final GifImage rotate180(GifImage gifImage);
public static final GifImage scale(GifImage gifImage,
double xscale, double yscale, boolean smooth);
public static final GifImage resize(GifImage gifImage,
int width, int height, boolean smooth);
public static final GifImage flipHorizontal(GifImage gifImage);
public static final GifImage flipVertical(GifImage gifImage);
Note:
smooth parameter (if presents) lets Java developers choose a gif image processing algorithm:
if 'true' then the higher priority is given to a gif image smoothness than processing speed.
But on the other hand it can bring about sizeable increase of the transformed GIF image size.
Gif4J PRO Java Example: Resize a GIF image using GifTransformer
// ...
// resize gif image to the width=100px
// with maintaining the aspect ratio of the original gif image dimension
GifImage resizedGifImage1 = GifTransformer.resize(gifImage, 100, -1, false);
// the same but smoothly
GifImage resizedGifImage1_smooth = GifTransformer.resize(gifImage, 100, -1, true);
// resize gif image to the width=100px and height=60px
GifImage resizedGifImage2 = GifTransformer.resize(gifImage, 100, 60, false);
// the same but smoothly
GifImage resizedGifImage2_smooth = GifTransformer.resize(gifImage, 100, 60, true);
// ...
| Resized GIF Images (the test image is out logo) |
|
|
|
[100, -1]
|
[100, -1, smoothly]
|
|
|
|
[100, 60]
|
[100, 60, smoothly]
|
Gif4J PRO Java Example: Scale a GIF image using GifTransformer
// ...
// scale gif image by factor 0.7 with maintaining
// the aspect ratio of the original gif image dimension
GifImage scaledGifImage1 = GifTransformer.scale(gifImage, 0.7, -1, false);
// the same but smoothly
GifImage scaledGifImage1_smooth = GifTransformer.scale(gifImage, 0.7, -1, true);
// scale gif image by X-axis scale factor = 1.2 and Y-axis scale factor = 0.8
GifImage scaledGifImage2 = GifTransformer.scale(gifImage, 1.2, 0.8, false);
// the same but smoothly
GifImage scaledGifImage2_smooth = GifTransformer.scale(gifImage, 1.2, 0.8, true);
// ...
| Scaled GIF Images (the test image is out logo) |
|
|
|
[0.7, -1]
|
[0.7, -1, smoothly]
|
|
|
|
[1.2, 0.8]
|
[1.2, 0.8, smoothly]
|
Gif4J PRO Java Example: Rotate a GIF image using GifTransformer
// ...
// rotate gif image by 45 degrees (PI/4 radians)
GifImage rotatedGifImage45 = GifTransformer.rotate(gifImage, Math.PI/4, false);
// the same but smoothly
GifImage rotatedGifImage45_smooth = GifTransformer.rotate(gifImage, Math.PI/4,true);
// 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);
// ...
| Rotated GIF Images (the test image is out logo) |
|
|
[45 degrees (PI/4 radians)]
|
|
|
[45 degrees (PI/4 radians), smooth]
|
|
|
|
[90 degrees counter-clockwise]
|
[90 degrees clockwise]
|
|
|
[180 degrees]
|
Gif4J PRO Java Example: Flip a GIF image using GifTransformer
// ...
// flip gif image vertically
GifImage flipVerticalGifImage = GifTransformer.flipVertical(gifImage);
// flip gif image horizontally (mirror gif image)
GifImage flipHorizontalGifImage = GifTransformer.flipHorizontal(gifImage);
// ...
| Flip GIF Images (the test image is out logo) |
|
|
|
[vertically]
|
[horizontally]
|
|  |