...
> Is there anyway to resize animated gif image using java tech.
This is the code now im using for animated gif resizing.
But the thing is this will not work in my debian enviroment.
I set DISPLAY veriable as 'export DISPLAY=:1.0' than it works in
console application. but not in Tomcat enviroment.
* How can I set DISPLAY in Tomcat5?
* Can anybody point me to right direction on this issue?
Thanks in advance
package test.image;
/**
* @@author Dishan Fernando
*
*/
import java.awt.image.BufferedImage;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class CGif {
String srcFileName = null;
String dstFileName = null;
FileOutputStream fileOutputStream = null;
public CGif(String srcFileName, String dstFileName) throws
FileNotFoundException{
this.srcFileName = srcFileName;
this.dstFileName = dstFileName;
this.fileOutputStream = new FileOutputStream(dstFileName);
}
public void saveAsFormattedGif(int width, int height) throws
IOException{
GifDecoder gifDecoder = new GifDecoder();
AnimatedGifEncoder animatedGifEncoder = new AnimatedGifEncoder();
gifDecoder.read(this.srcFileName);
int frameCount = gifDecoder.getFrameCount();
int loopCount = gifDecoder.getLoopCount();
animatedGifEncoder.setRepeat(loopCount);
animatedGifEncoder.start(fileOutputStream);
for (int frameNumber = 0; frameNumber < frameCount; frameNumber++) {
BufferedImage frame = gifDecoder.getFrame(frameNumber); // frame
i
int delay = gifDecoder.getDelay(frameNumber); // display
duration of frame in milliseconds
animatedGifEncoder.setDelay(delay); // frame delay per sec
animatedGifEncoder.addFrame( CUtil.resizeToMaxAndCrop(frame,
width, height) );
}
animatedGifEncoder.finish();
fileOutputStream.flush();
fileOutputStream.close();
}
public static void main(String[] args) {
try {
CGif gif = new CGif("E:\\10512Decorations_400x400.gif", "E:\
\128x128.gif");
gif.saveAsFormattedGif(128, 128);
System.out.println("done!");
} catch (Exception e) {
e.printStackTrace();
}
}
}
Andrew Thompson - 21 Feb 2007 11:08 GMT
> This is the code now im using for animated gif resizing.
> But the thing is this will not work in my debian enviroment.
...
> import java.awt.image.BufferedImage;
> import java.io.FileNotFoundException;
> import java.io.FileOutputStream;
> import java.io.IOException;
...
> GifDecoder gifDecoder = new GifDecoder();
> AnimatedGifEncoder animatedGifEncoder = new AnimatedGifEncoder();
...
Where are the imports for these classes?
It seems (from vague memory) you are now
using the library made by Kevin Weiner to
decode/encode the GIF's, but I cannot see
where they are imported to the code.
Andrew T.
D i s h a n - 22 Feb 2007 03:37 GMT
Its in my current package folder.
Andrew Thompson - 22 Feb 2007 13:12 GMT
> Its in my current package folder.
I looked at the code more closely thatn your
other words. What is 'export DISPLAY=:1.0'?
I do not see it referenced anywhere else in
the code.
If it is a screen ratio, there may be a problem
because the code is working in a 'headless' or
non GUI'd environment in tomcat.
Andrew T.
Lars Enderin - 22 Feb 2007 13:30 GMT
Andrew Thompson skrev:
>> Its in my current package folder.
>
[quoted text clipped - 6 lines]
> because the code is working in a 'headless' or
> non GUI'd environment in tomcat.
DISPLAY is an environment variable used in Unix/Linux to tell the X
Windows system where (on which physical/logical screen) output should be
displayed. Tomcat should not interact with X Windows.
Gordon Beaton - 22 Feb 2007 13:26 GMT
> This is the code now im using for animated gif resizing.
> But the thing is this will not work in my debian enviroment.
> I set DISPLAY veriable as 'export DISPLAY=:1.0' than it works in
> console application. but not in Tomcat enviroment.
> * How can I set DISPLAY in Tomcat5?
> * Can anybody point me to right direction on this issue?
If Tomcat runs as a daemon or under control of a web server, then
setting DISPLAY or even assuming there is a display is not the right
approach.
There are a number of reasons why system daemons should not attempt to
connect to a display or even assume the existence of one.
Have you tried setting -Djava.awt.headless=true?
/gordon

Signature
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e