Resize Animated GIF Image

Discussion in 'Java' started by D i s h a n, Feb 13, 2007.

  1. D i s h a n

    D i s h a n Guest

    Hi Experts,

    Is there anyway to resize animated gif image using java tech.

    Thanks in advance

    DF
     
    D i s h a n, Feb 13, 2007
    #1
    1. Advertising

  2. D i s h a n

    bugbear Guest

    D i s h a n wrote:
    > Hi Experts,
    >
    > Is there anyway to resize animated gif image using java tech.


    I don't know a direct answer.

    I think java can do 2D zooming, so the answer would
    be "yes" if you can get the induividual frames
    our, zoom, and ressemble.

    As a side FYI, I think ImageMagick can do it in one hit.

    BugBear
     
    bugbear, Feb 13, 2007
    #2
    1. Advertising

  3. On Feb 13, 10:12 pm, "D i s h a n" <> wrote:
    ....
    > Is there anyway to resize animated gif image using java tech.


    Is that a question? Note that adding '?'
    helps the reader to identify the question,
    and you would want to *help* people, to
    help you, no?

    In any case..

    Sure. Bugbear probably identified the
    robust and correct approach, so I'll
    just jump in with another that is quick
    and (very) hackish.

    <sscce>
    import javax.swing.*;
    import java.io.File;
    import java.net.URL;

    /**
    Swing components can parse simple HTML like..

    <html>
    <body bgcolor='black'>
    <img src='./plnttm.gif' width='150' height='150' ><br>
    <img src='./plnttm.gif' width='300' height='300' >
    </body>
    </html>

    'pntthmb.gif is an animated GIF in the same
    directory as the HTML.
    */
    class ResizeableAnimatedImage extends JPanel {

    public static void main(String[] args) throws Exception {
    JEditorPane jep = new JEditorPane();
    File file = new File( ".","images.html" );
    URL url = file.toURI().toURL();
    jep.setPage(url);

    JOptionPane.
    showMessageDialog( null, jep );
    }
    }
    </sscce>

    HTH

    Andrew T.
     
    Andrew Thompson, Feb 13, 2007
    #3
  4. D i s h a n

    D i s h a n Guest

    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();
    }
    }
    }
     
    D i s h a n, Feb 21, 2007
    #4
  5. On Feb 21, 4:37 pm, "D i s h a n" <> wrote:
    > 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.
     
    Andrew Thompson, Feb 21, 2007
    #5
  6. D i s h a n

    D i s h a n Guest

    Its in my current package folder.
     
    D i s h a n, Feb 22, 2007
    #6
  7. On Feb 22, 2:37 pm, "D i s h a n" <> wrote:
    > 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.
     
    Andrew Thompson, Feb 22, 2007
    #7
  8. On 20 Feb 2007 21:37:59 -0800, D i s h a n wrote:
    > 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

    --
    [ 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
     
    Gordon Beaton, Feb 22, 2007
    #8
  9. D i s h a n

    Lars Enderin Guest

    Andrew Thompson skrev:
    > On Feb 22, 2:37 pm, "D i s h a n" <> wrote:
    >> 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.


    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.
     
    Lars Enderin, Feb 22, 2007
    #9
  10. D i s h a n

    rt29

    Joined:
    Feb 25, 2012
    Messages:
    1
    Although its too late but the open source library for Gif Animation Resize in java is available at http://www.jgifcode.com
     
    rt29, Feb 25, 2012
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JW
    Replies:
    2
    Views:
    752
  2. christof hoeke

    save animated GIF in Python Image Library

    christof hoeke, Feb 5, 2004, in forum: Python
    Replies:
    1
    Views:
    2,947
    Fredrik Lundh
    Feb 24, 2004
  3. Dave Kelly
    Replies:
    4
    Views:
    835
    natashab
    Nov 30, 2006
  4. David C

    Animated gif image

    David C, Dec 4, 2009, in forum: ASP .Net
    Replies:
    0
    Views:
    359
    David C
    Dec 4, 2009
  5. Iseng ---
    Replies:
    0
    Views:
    212
    Iseng ---
    Jul 22, 2006
Loading...

Share This Page