Resizing animated GIF using JIMI.

Hi everybody,
I have a very simple question: how can i resize an animated gif using JIMI?
what i can do now is open the gif resize it and save it as a jpeg pic, but the animation dosen't normally remain. i want to save it as a gif thus the animation info remains.
when i try saving it using this code:
try{
                Jimi.putImage("image/gif",new_image,destination);
            catch(JimiException je){
                System.err.println("JimiException: " + je.toString());
            }i get this exception:
com.sun.jimi.core.JimiException: Cannot find encoder for type: image/gif.
Where can i find a gif encoder for JIMI?
Please help.

Jimi doesn't support GIF encoding and I afraid not support resizing animated GIFs but resize only the first frame. To resize animated GIFs I suggest to use Gif4J (http://www.gif4j.com): it's commercial but it works and works very well.

Similar Messages

  • Identifying/resizing animated GIF

    Hi
    This is my situation: I load user-selected image files (any format is OK, the more the better) for later transmission as byte array, always re-encoded as JPG. If the image is over some certain width/height, I scale down the image (display size issues). Until now I was reading the images with ImageIO.read, downsizing with Graphics2D.drawImage and encoding with ImageIO.write, and everything works nicely.
    Now I need to support animated GIFs as well. The current method makes animated gifs as a static first frame of the animation. My two alternatives are:
    1 - support animated GIF downsizing
    2 - detecting animated GIFs and handling them separately (no resize allowed, no re-encode)
    The first alternative sounds cumbersome, Googling around showed problems with lost transparency and requiring to downsize all frames separately and then re-encode. If I have to do this extract-downsize-encode I won't take this route, better do not perform animated GIF resizing. The second alternative sounds much simpler, and less problem-prone.
    Now I would like suggestions on how can I archive this. I'd really appreciate some code/lib to detect and optionally resize animated GIFs. It must be a free code solution.
    The only animated GIF detection code I found was this, but it requires looking for certain bytes, and I'd like a more robust solution (also it didn't worked).
    I would like to keep using ImageIO API rather than older APIs, as it seems to provide better image format support and is way simpler. A lib to do the GIF part of the job is fine.
    Thanks!

    This is my situation: I load user-selected image files (any format is OK, the more the better) for later transmission as byte array, always re-encoded as JPG. If the image is over some certain width/height, I scale down the image (display size issues).If they are JPEGs that is entirely the wrong solution. You are losing far too much image quality. What you should be doing here is saving with a lower 'q'. That's exactly what it's for - intelligent compression of images. You are just doing naive resampling. JPEG can do far better than that.
    I worked on a project where somebody downsized thousands of images like this, entirely the wrong way. Don't repeat this mistake.
    As to the rest, sounds like you need a GIF plugin for ImageIO that will let you read the header.

  • Resizing animated GIF

    Hi all,
    does anybody know how to handle (scale, resize etc.) animated GIF image using Java? Any sample or reference would be great.
    Thx,
    My e-mail info: http://www.captchaprotected.com/get.jsp?id=0QdjN0k02J

    Jimi doesn't support GIF encoding and I afraid not support resizing animated GIFs but resize only the first frame. To resize animated GIFs I suggest to use Gif4J (http://www.gif4j.com): it's commercial but it works and works very well.

  • Create animated GIF using imageio

    How do you create an animated GIF using the J2SE's javax.imageio classes?
    I have been browsing these 3 threads (one of which I participated in) to try and develop an SSCCE of creating an animated GIF.
    [Writing out animated gifs with ImageIO?|http://forums.sun.com/thread.jspa?threadID=5204877]
    [Wirting image metadata to control animated gif delays |http://forums.java.net/jive/thread.jspa?messageID=214284&]
    [Help with GIF writer in imageio|http://www.javakb.com/Uwe/Forum.aspx/java-programmer/32892/Help-with-GIF-writer-in-imageio]
    (pity I did not prompt the OP on that last one, to supply an SSCCE.)
    Unfortunately, my efforts so far have been dismal. Either, without the IIOMetadata object, the GIF has frames with no delay, and it cycles just once, or with the IIOMetadata object I get an error.
    IIOInvalidTreeException: Unknown child of root node!Can anyone point me in the right direction?
    import java.awt.*;
    import java.awt.image.*;
    import javax.swing.*;
    import java.io.*;
    import java.net.URL;
    import java.util.Iterator;
    import javax.imageio.*;
    import javax.imageio.metadata.*;
    import javax.imageio.stream.*;
    import org.w3c.dom.Node;
    class WriteAnimatedGif {
      /** Adapted from code via Brian Burkhalter on
      http://forums.java.net/jive/thread.jspa?messageID=214284& */
      public static Node getRootNode(String delayTime) {
        IIOMetadataNode root =
          new IIOMetadataNode("javax_imageio_gif_stream_1.0");
        IIOMetadataNode gce =
          new IIOMetadataNode("GraphicControlExtension");
        gce.setAttribute("disposalMethod", "none");
        gce.setAttribute("userInputFlag", "FALSE");
        gce.setAttribute("transparentColorFlag", "FALSE");
        gce.setAttribute("delayTime", delayTime);
        gce.setAttribute("transparentColorIndex", "255");
        root.appendChild(gce);
        IIOMetadataNode aes =
          new IIOMetadataNode("ApplicationExtensions");
        IIOMetadataNode ae =
          new IIOMetadataNode("ApplicationExtension");
        ae.setAttribute("applicationID", "NETSCAPE");
        ae.setAttribute("authenticationCode", "2.0");
        byte[] uo = new byte[] {
          (byte)0x21, (byte)0xff, (byte)0x0b,
          (byte)'N', (byte)'E', (byte)'T', (byte)'S',
          (byte)'C', (byte)'A', (byte)'P', (byte)'E',
          (byte)'2', (byte)'.', (byte)'0',
          (byte)0x03, (byte)0x01, (byte)0x00, (byte)0x00,
          (byte)0x00
        ae.setUserObject(uo);
        aes.appendChild(ae);
        root.appendChild(aes);
        return root;
      /** Adapted from code via GeogffTitmus on
      http://forums.sun.com/thread.jspa?messageID=9988198 */
      public static File saveAnimate(
        BufferedImage[] frames,
        String name,
        String delayTime) throws Exception {
        File file = null;
        file = new File(name+".gif");
        Node root = getRootNode(delayTime);
        ImageWriter iw = ImageIO.getImageWritersByFormatName("gif").next();
        ImageOutputStream ios = ImageIO.createImageOutputStream(file);
        iw.setOutput(ios);
        //IIOImage ii = new IIOImage(frames[0], null, null);
        //IIOMetadata im = iw.getDefaultStreamMetadata(null);
        //IIOMetadata im = new AnimatedIIOMetadata();
        //im.setFromTree("gif", root);
        iw.prepareWriteSequence(null);
        for (int i = 0; i < frames.length; i++) {
          BufferedImage src = frames;
    ImageWriteParam iwp = iw.getDefaultWriteParam();
    IIOMetadata metadata = iw.getDefaultStreamMetadata(iwp);
    System.out.println( "IIOMetadata: " + metadata );
    //metadata.mergeTree(metadata.getNativeMetadataFormatName(), root);
    metadata.setFromTree(metadata.getNativeMetadataFormatName(), root);
    //Node root = metadata.getAsTree("javax_imageio_gif_image_1.0");
    IIOImage ii = new IIOImage(src, null, metadata);
    iw.writeToSequence( ii, (ImageWriteParam)null);
    iw.endWriteSequence();
    ios.close();
    return file;
    public static void main(String[] args) throws Exception {
    // uncomment the other two if you like, but we can
    // see it work or fail with just the first and last.
    String[] names = {
    "bronze",
    //"silver",
    //"gold",
    "platinum"
    String pre = "http://forums.sun.com/im/";
    String suff = "-star.gif";
    BufferedImage[] frames = new BufferedImage[names.length];
    for (int ii=0; ii<names.length; ii++) {
    URL url = new URL(pre + names[ii] + suff);
    System.out.println(url);
    frames[ii] = ImageIO.read(url);
    File f = saveAnimate(frames, "animatedstars", "500");
    JOptionPane.showMessageDialog( null, new ImageIcon(f.toURI().toURL()) );
    Desktop.getDesktop().open(f);
    ImageInputStream iis = ImageIO.createImageInputStream(f);
    //System.out.println("ImageReader: " + ir1);
    //System.out.println("IIOMetadata: " + ir1.getStreamMetadata());
    Iterator itReaders = ImageIO.getImageReaders(iis);
    while (itReaders.hasNext() ) {
    ImageReader ir = (ImageReader)itReaders.next();
    System.out.println("ImageReader: " + ir);
    System.out.println("IIOMetadata: " + ir.getStreamMetadata());

    According to imagio's [gif metadata specification|http://java.sun.com/javase/6/docs/api/javax/imageio/metadata/doc-files/gif_metadata.html], the metadata you are specifying is image-specific metadata. The stream metadata is global metadata applicable to all the images.
    So change this,
    IIOMetadataNode root =
        new IIOMetadataNode("javax_imageio_gif_stream_1.0");to this,
    IIOMetadataNode root =
        new IIOMetadataNode("javax_imageio_gif_image_1.0");and this,
    IIOMetadata metadata = iw.getDefaultStreamMetadata(iwp);
    System.out.println( "IIOMetadata: " + metadata );
    //metadata.mergeTree(metadata.getNativeMetadataFormatName(), root);
    metadata.setFromTree(metadata.getNativeMetadataFormatName(), root);
    //Node root = metadata.getAsTree("javax_imageio_gif_image_1.0");to this,
    IIOMetadata metadata = iw.getDefaultImageMetadata(
            new ImageTypeSpecifier(src),null);
    System.out.println("IIOMetadata: " + metadata);
    metadata.mergeTree(metadata.getNativeMetadataFormatName(), root);Here is your program again, but with the above changes.
    import java.awt.*;
    import java.awt.image.*;
    import javax.swing.*;
    import java.io.*;
    import java.net.URL;
    import java.util.Iterator;
    import javax.imageio.*;
    import javax.imageio.metadata.*;
    import javax.imageio.stream.*;
    import org.w3c.dom.Node;
    class WriteAnimatedGif {
        /** Adapted from code via Brian Burkhalter on
        http://forums.java.net/jive/thread.jspa?messageID=214284& */
        public static Node getRootNode(String delayTime) {
            IIOMetadataNode root =
                    new IIOMetadataNode("javax_imageio_gif_image_1.0");
            IIOMetadataNode gce =
                    new IIOMetadataNode("GraphicControlExtension");
            gce.setAttribute("disposalMethod", "none");
            gce.setAttribute("userInputFlag", "FALSE");
            gce.setAttribute("transparentColorFlag", "FALSE");
            gce.setAttribute("delayTime", delayTime);
            gce.setAttribute("transparentColorIndex", "255");
            root.appendChild(gce);
            IIOMetadataNode aes =
                    new IIOMetadataNode("ApplicationExtensions");
            IIOMetadataNode ae =
                    new IIOMetadataNode("ApplicationExtension");
            ae.setAttribute("applicationID", "NETSCAPE");
            ae.setAttribute("authenticationCode", "2.0");
            byte[] uo = new byte[]{
                (byte) 0x21, (byte) 0xff, (byte) 0x0b,
                (byte) 'N', (byte) 'E', (byte) 'T', (byte) 'S',
                (byte) 'C', (byte) 'A', (byte) 'P', (byte) 'E',
                (byte) '2', (byte) '.', (byte) '0',
                (byte) 0x03, (byte) 0x01, (byte) 0x00, (byte) 0x00,
                (byte) 0x00
            ae.setUserObject(uo);
            aes.appendChild(ae);
            root.appendChild(aes);
            return root;
        /** Adapted from code via GeogffTitmus on
        http://forums.sun.com/thread.jspa?messageID=9988198 */
        public static File saveAnimate(
                BufferedImage[] frames,
                String name,
                String delayTime) throws Exception {
            File file = null;
            file = new File(name + ".gif");
            Node root = getRootNode(delayTime);
            ImageWriter iw = ImageIO.getImageWritersByFormatName("gif").next();
            ImageOutputStream ios = ImageIO.createImageOutputStream(file);
            iw.setOutput(ios);
            //IIOImage ii = new IIOImage(frames[0], null, null);
            //IIOMetadata im = iw.getDefaultStreamMetadata(null);
            //IIOMetadata im = new AnimatedIIOMetadata();
            //im.setFromTree("gif", root);
            iw.prepareWriteSequence(null);
            for (int i = 0; i < frames.length; i++) {
                BufferedImage src = frames;
    ImageWriteParam iwp = iw.getDefaultWriteParam();
    IIOMetadata metadata = iw.getDefaultImageMetadata(
    new ImageTypeSpecifier(src), null);
    System.out.println("IIOMetadata: " + metadata);
    metadata.mergeTree(metadata.getNativeMetadataFormatName(), root);
    IIOImage ii = new IIOImage(src, null, metadata);
    iw.writeToSequence(ii, (ImageWriteParam) null);
    iw.endWriteSequence();
    ios.close();
    return file;
    public static void main(String[] args) throws Exception {
    // uncomment the other two if you like, but we can
    // see it work or fail with just the first and last.
    String[] names = {
    "bronze",
    //"silver",
    //"gold",
    "platinum"
    String pre = "http://forums.sun.com/im/";
    String suff = "-star.gif";
    BufferedImage[] frames = new BufferedImage[names.length];
    for (int ii = 0; ii < names.length; ii++) {
    URL url = new URL(pre + names[ii] + suff);
    System.out.println(url);
    frames[ii] = ImageIO.read(url);
    File f = saveAnimate(frames, "animatedstars", "500");
    JOptionPane.showMessageDialog(null, new ImageIcon(f.toURI().toURL()));
    Desktop.getDesktop().open(f);
    ImageInputStream iis = ImageIO.createImageInputStream(f);
    //System.out.println("ImageReader: " + ir1);
    //System.out.println("IIOMetadata: " + ir1.getStreamMetadata());
    Iterator itReaders = ImageIO.getImageReaders(iis);
    while (itReaders.hasNext()) {
    ImageReader ir = (ImageReader) itReaders.next();
    System.out.println("ImageReader: " + ir);
    System.out.println("IIOMetadata: " + ir.getStreamMetadata());

  • Set frame delay time for animated gif using ImageIO

    I'm trying to change the delay time of each frame for an animated gif by changing the metadata for each frame as following but it doesn't change anything.
    static private IIOMetadata setMetadata(IIOMetadata metadata, int delayMS) throws IOException
              Node root = metadata.getAsTree("javax_imageio_gif_image_1.0");
              for (Node c = root.getFirstChild(); c != null; c = c.getNextSibling())
                   String name = c.getNodeName();
                   if (c instanceof IIOMetadataNode)
                        IIOMetadataNode metaNode = (IIOMetadataNode) c;
                        if ("GraphicControlExtension".equals(name))
                             metaNode.setAttribute("delayTime", Integer.toString(delayMS));
         }Does anyone know how to set delay time for animated gif using ImageIO ?

    I'm trying to change the delay time of each frame for an animated gif by changing the metadata for each frame as following but it doesn't change anything.
    static private IIOMetadata setMetadata(IIOMetadata metadata, int delayMS) throws IOException
              Node root = metadata.getAsTree("javax_imageio_gif_image_1.0");
              for (Node c = root.getFirstChild(); c != null; c = c.getNextSibling())
                   String name = c.getNodeName();
                   if (c instanceof IIOMetadataNode)
                        IIOMetadataNode metaNode = (IIOMetadataNode) c;
                        if ("GraphicControlExtension".equals(name))
                             metaNode.setAttribute("delayTime", Integer.toString(delayMS));
         }Does anyone know how to set delay time for animated gif using ImageIO ?

  • Resized animated gif ImageIcon not working properly with JButton etc.

    The problem is that when I resize an ImageIcon representing an animated gif and place it on a Jbutton, JToggelButton or JLabel, in some cases the image does not show or does not animate. More precicely, depending on the specific image file, the image shows always, most of the time or sometimes. Images which are susceptible to not showing often do not animate when showing. Moving over or clicking with the mouse on the AbstractButton instance while the frame is supposed to updated causes the image to disappear (even when viewing the non-animating image that sometimes appears). No errors are thrown.
    Here some example code: (compiled with Java 6.0 compliance)
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Test
         public static void main(String[] args)
              new Test();
         static final int  IMAGES        = 3;
         JButton[]           buttons       = new JButton[IMAGES];
         JButton             toggleButton  = new JButton("Toggle scaling");
         boolean            doScale       = true;
         public Test()
              JFrame f = new JFrame();
              f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              JPanel p = new JPanel(new GridLayout(1, IMAGES));
              for (int i = 0; i < IMAGES; i++)
                   p.add(this.buttons[i] = new JButton());
              f.add(p, BorderLayout.CENTER);
              f.add(this.toggleButton, BorderLayout.SOUTH);
              this.toggleButton.addActionListener(new ActionListener() {
                   @Override
                   public void actionPerformed(ActionEvent e)
                        Test.this.refresh();
              f.setSize(600, 300);
              f.setVisible(true);
              this.refresh();
         public void refresh()
              this.doScale = !this.doScale;
              for (int i = 0; i < IMAGES; i++)
                   ImageIcon image = new ImageIcon(i + ".gif");
                   if (this.doScale)
                        image = new ImageIcon(image.getImage().getScaledInstance(180, 180, Image.SCALE_AREA_AVERAGING));
                   image.setImageObserver(this.buttons);
                   this.buttons[i].setIcon(image);
                   this.buttons[i].setSelectedIcon(image);
                   this.buttons[i].setDisabledIcon(image);
                   this.buttons[i].setDisabledSelectedIcon(image);
                   this.buttons[i].setRolloverIcon(image);
                   this.buttons[i].setRolloverSelectedIcon(image);
                   this.buttons[i].setPressedIcon(image);
    Download the gif images here:
    http://djmadz.com/zombie/0.gif
    http://djmadz.com/zombie/1.gif
    http://djmadz.com/zombie/2.gif
    When you press the "Toggle scaling"button it switches between unresized (properly working) and resized instances of three of my gif images. Notice that the left image almost never appears, the middle image always, and the right image most of the time. The right image seems to (almost) never animate. When you click on the left image (when visble) it disappears only when the backend is updating the animation (between those two frames with a long delay)
    Why are the original ImageIcon and the resized ImageIcon behaving differently? Are they differently organized internally?
    Is there any chance my way of resizing might be wrong?

    It does work, however I refuse to use SCALE_REPLICATE for my application because resizing images is butt ugly, whether scaling up or down. Could there be a clue in the rescaling implementations, which I can override?
    Maybe is there a way that I can check if an image is a multi-frame animation and set the scaling algorithm accordingly?
    Message was edited by:
    Zom-B

  • How to resize animated gif without losing animation?

    I created a wee animated gif a while ago but deleted the original Photoshop file (CS3). I need to resize the gif from 100px to 70px for an avatar. When I've changed the image size in Photoshop (it doesn't show the animation frames), it removes all animation. Is there a way around this?
    Kind regards
    Mel
    The image:

    You can infact use Adobe Macromedia Flash to resize your Gif Image.
    Import your Gif image into Flash and then you can try to resize and export the file as GIF.
    Its kinda weird but it works . 

  • How To Resize Animated GIF's All At Once?

    I have seen people say you can resize an animated GIF in
    Fireworks without doing it one frame at a time, but nobody says
    exactly how. Maybe I'm missing something simple, but is this
    possibe and if so, how do you do it?
    I tried using the forum search but it didn't find any
    results.
    I'm using Fireworks 9.0.1.1213 if that makes a
    difference.

    If you look in the frames window, you will see that each
    frame has a gray
    box on the left. Click that gray box by the first frame and
    the last frame
    to turn on onion skinning. You'll know if it worked because
    there will be
    two little icons, one pointing up and the other pointing
    down, with a line
    connecting them through all the onion skinned frames.
    HTH;
    Amy
    "Louie55" <[email protected]> wrote in
    message
    news:fum5i1$s9c$[email protected]..
    >I have seen people say you can resize an animated GIF in
    Fireworks without
    > doing it one frame at a time, but nobody says exactly
    how. Maybe I'm
    > missing
    > something simple, but is this possibe and if so, how do
    you do it?
    >
    > I tried using the forum search but it didn't find any
    results.
    >
    > I'm using Fireworks 9.0.1.1213 if that makes a
    difference.
    >

  • Problem to create animated gif using transparent frames

    Hi, everyone:
    My name is Edison, I am playing with Gif89Encoder utility classes to make an animated gif which is a requirement for my course work.
    I got some problem about the transparent frames. I used the png image as the frame to create the animated gif,
    those pngs have transparent colors and the background is totally transparent, when i create the animated the gif with those
    frames, the animated gif display the colors but without transparency for those colors, but the background is transparent as expected.
    I am not sure if I should IndexGif89Frame or DirectGif89Frame for the colors from the Gif89encoder package.
    Is there anyone got the same problem and knows how to fix it?
    The following is how i setup the colors in my png file, the alpha channel is 80.
    Color[] colours = new Color[7];
              colours[0] = new Color(255, 255, 255, 0);
              colours[1] = new Color(128, 128, 255, 80);
              colours[2] = new Color(128, 0, 128, 80);
              colours[3] = new Color(0, 128, 128, 80);
              colours[4] = new Color(128, 128, 0, 80);
              colours[5] = new Color(204,102,255,80);
              colours[6] = new Color(255, 0, 0, 80);The code i did to generate gif:
    public void run89Gif()
            Image[] images = new Image[4];    
            try{
                images[0] = ImageIO.read(new File("D:/temp/0.png"));
                images[1] = ImageIO.read(new File("D:/temp/1.png"));
                images[2] = ImageIO.read(new File("D:/temp/2.png"));
                images[3] = ImageIO.read(new File("D:/temp/3.png"));
                OutputStream out = new FileOutputStream("D:/temp/output.gif");
                writeAnimatedGIF(images,"Empty annotation", true, 1, out);         
                images = null;
            }catch(IOException er){ }
    static void writeAnimatedGIF(
            Image[] still_images,
                String annotation,
                boolean looped,
                double frames_per_second,
                OutputStream out) throws IOException
            Gif89Encoder gifenc = new Gif89Encoder();
            for (int i = 0; i < still_images.length; ++i){
               gifenc.addFrame(still_images);
    gifenc.setComments(annotation);
    gifenc.setLoopCount(looped ? 0 : 1);
    gifenc.setUniformDelay((int) Math.round(100 / frames_per_second));
    gifenc.encode(out);
    Thanks in advance.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Hi, everyone:
    My name is Edison, I am playing with Gif89Encoder utility classes to make an animated gif which is a requirement for my course work.
    I got some problem about the transparent frames. I used the png image as the frame to create the animated gif,
    those pngs have transparent colors and the background is totally transparent, when i create the animated the gif with those
    frames, the animated gif display the colors but without transparency for those colors, but the background is transparent as expected.
    I am not sure if I should IndexGif89Frame or DirectGif89Frame for the colors from the Gif89encoder package.
    Is there anyone got the same problem and knows how to fix it?
    The following is how i setup the colors in my png file, the alpha channel is 80.
    Color[] colours = new Color[7];
              colours[0] = new Color(255, 255, 255, 0);
              colours[1] = new Color(128, 128, 255, 80);
              colours[2] = new Color(128, 0, 128, 80);
              colours[3] = new Color(0, 128, 128, 80);
              colours[4] = new Color(128, 128, 0, 80);
              colours[5] = new Color(204,102,255,80);
              colours[6] = new Color(255, 0, 0, 80);The code i did to generate gif:
    public void run89Gif()
            Image[] images = new Image[4];    
            try{
                images[0] = ImageIO.read(new File("D:/temp/0.png"));
                images[1] = ImageIO.read(new File("D:/temp/1.png"));
                images[2] = ImageIO.read(new File("D:/temp/2.png"));
                images[3] = ImageIO.read(new File("D:/temp/3.png"));
                OutputStream out = new FileOutputStream("D:/temp/output.gif");
                writeAnimatedGIF(images,"Empty annotation", true, 1, out);         
                images = null;
            }catch(IOException er){ }
    static void writeAnimatedGIF(
            Image[] still_images,
                String annotation,
                boolean looped,
                double frames_per_second,
                OutputStream out) throws IOException
            Gif89Encoder gifenc = new Gif89Encoder();
            for (int i = 0; i < still_images.length; ++i){
               gifenc.addFrame(still_images);
    gifenc.setComments(annotation);
    gifenc.setLoopCount(looped ? 0 : 1);
    gifenc.setUniformDelay((int) Math.round(100 / frames_per_second));
    gifenc.encode(out);
    Thanks in advance.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Applet Parameters For Animated Gif Using AWT

    I need to have my applet except parameters to change from one type of animated gif (dog) to another animated gif (cat). There are two for each animal. If the animal parameter is "dog" the dog1.gif and the dog2.gif will be used for the animation. I'm not too sure on how to go about this.
    private String sDog;
    private String sCat;
    sDog = getParameter("");
    if (sDog.equalsIgnoreCase("dog"))
    How do I add both gifs in the control statement?
    Thanks so much,
    Jeff

    private String sDog;
    private String sCat;
    sDog = getParameter("dog");
    for(int i=1;i<3;i++){
    if (sDog.equalsIgnoreCase("dog" i".gif"))
    //code to display the gif
    remember your parameter should be <b>dog</b>

  • Creating animated GIF using Photoshop Scripting

    Hi,
    I am trying to mimic the action "Save for Web & Devices" of a PSD file, having 4 frames in an animation, into an animated GIF file.
    I was suggested to use "ScriptingListener", but I did the copy/paste of the code, it did not work.
    Is there a way to code a script, by using classes/functions to achieve this result ?
    Thank you in advance.
    Jean-Louis

    Yes that's my understanding for Javascript, with clarification that with "compile them all into animated GIF through script" using some external program (e.g. check out ImageMagick). Whether that is an OK solution depends on what you are trying to do (just for own internal use or distribution).
    For the Javascript docs see http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/photoshop/pdfs/photoshop-cc-javascr ipt-ref.pdf

  • Creating Animated GIF using Frames

    I would like to create an animated gif without using the 'tween' tool. Basically, I'd like to have an object move across the screen, stop at one point, perform a task (i.e., move arms/legs up and down in a 'jumping jack' style) and then continue on across the screen. I create the first frame then click on the 'duplicate frame' icon. In this frame I use the puppet warp feature to change the position of my object's arms/legs. Next, I duplicate the frame again and repeat the puppet warp process. Finally, I continue to duplicate the frames, moving the object 'x' spaces each frame until it finishes its journey across the screen.
    Unfortunately, when I change the position of my object's legs/arms, it changes all of them across all frames. However, the program still allows the object to continue its journey across the screen.
    Because of this, I have had to create separate jpg files for each and every one of the object position changes, then import each one with the 'place' tool into the layers and finally create frames from layers and save the gif that way.
    Is there a way to do the above without having to create a separate jpg for each one?

    Hi SweetFang,
    If you're using the Puppet Warp tool, I may suggest you change your workflow. When you duplicate a frame, it doesn't necessarily duplicate the object that is being animated so each change you make will show up in every frame. Instead of duplicating frames to make your changes, try duplicating layers. It will be a good deal easier than saving out a .jpg for each image and then placing them in.
    1. Create your background.
    2. Create a new layer for the object you will animate. Position it how you want it to look in the first frame of your animation.
    3. Now, duplicate the layer and use the puppet transform tool to make your first change.
    4. Repeat this process: duplicate your most recent layer, make your change, duplicate your most recent layer, make your change, etc. (To keep your workspace clear you may want to make each previous layer invisible when you add a new one)
    5. When you're completely finished, open your Animation panel (CS5) or Timeline panel (CS6) and in the flyout menu, choose Make Frames From Layers
    This workflow is essentially what you're doing already, but you're duplicating layers instead of frames and then making the frames automatically.
    Please let me know if this makes your project a little bit smoother.
    Cheers,
    Michael

  • Resizing animated GIFs

    Hi,
    I use the following code to resize an ImageIcon (which is inside
    a JLabel) :
    public void resizeImageBean(ImageIcon icon, float width, float height) {
        Image img = icon.getImage();
        Image newImg = img.getScaledInstance((int) (width), (int) (height), Image.SCALE_DEFAULT);
        initImageBean(newImg);
    }//resizeImageBean
    private void initImageBean(Image img) {
        ImageIcon icon = new ImageIcon(img);
        imageLabel.setIcon(icon); // imageLabel is a JLabel
        repaint();
    }//initImageBeanThis code seems to work for most image formats, only with GIFs that
    are animated there is some strange behaviour.
    I have 3 cases:
    - Some GIF images are not being displayed anymore after resizing (empty JLabel)
    - Some GIF images are correctly resized, but the animation stops
    - Some GIF images are correctly resized and the animation is still ok.
    I fixed the first problem by changing the compression to interlaced if
    the gif was non-interlaced by using a freeware proggy called GiFFY.
    By doing this the images did resize but ended in one of the 2 last cases.
    Note: by changing the compression to interlaced, the images also showed
    up in the preview label of JFileChooser.
    Anyone has some thoughts on this ? Any feedback will be greatly appreciated.
    Greetings,
    Janiek

    Have you found the solution to your problems.If yes then please let me know how .I am facing simalar problems
    Some GIF images are not being displayed anymore after resizing (empty JLabel)
    - Some GIF images are correctly resized, but the animation stops
    - Some GIF images are correctly resized and the animation is still ok.
    Here's my code:
    import javax.swing.ImageIcon;
    import java.awt.image.*;
    import com.sun.image.codec.jpeg.*;
    import java.io.*;
    import java.awt.geom.*;
    import java.awt.image.*;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import javax.media.jai.*;
    import java.awt.image.renderable.ParameterBlock;
    import com.sun.media.jai.codec.*;
    //import javax.imageio.*;
    import java.awt.*;
    public class Photo
         public static void resize(String original, String resized, int wid,int het)
              try
                        File originalFile = new File(original);
                        ImageIcon ii = new ImageIcon(originalFile.getCanonicalPath());
                        Image i = ii.getImage();
                        System.out.println("Original image width"+i.getWidth(null));
                        System.out.println("Original image height"+i.getHeight(null));
                        Image resizedImage = null;
                        int iWidth = i.getWidth(null);
                        int iHeight = i.getHeight(null);
                        if (iWidth > iHeight)
                        resizedImage = i.getScaledInstance(wid,het,Image.SCALE_SMOOTH);
                        else
                        resizedImage = i.getScaledInstance(wid,het,Image.SCALE_SMOOTH);
                        // This code ensures that all the
                        // pixels in the image are loaded.
                        Image temp = new ImageIcon(resizedImage).getImage();
                        System.out.println("resizedImage width"+temp.getWidth(null));
                        System.out.println("resizedImage height"+temp.getHeight(null));
                        // Create the buffered image.
                        BufferedImage bufferedImage = new BufferedImage(temp.getWidth(null), temp.getHeight(null), BufferedImage.TYPE_INT_RGB);
                        // Copy image to buffered image.
                        Graphics g = bufferedImage.createGraphics();
                        // Clear background and paint the image.
                        g.setColor(Color.white);
                        g.fillRect(0, 0, temp.getWidth(null),temp.getHeight(null));
                        g.drawImage(temp, 0, 0, null);
                        g.dispose();
                        // sharpen
                        float[] sharpenArray = { 0, -1, 0, -1, 5, -1, 0, -1, 0 };
                        Kernel kernel = new Kernel(3, 3, sharpenArray);
                        ConvolveOp cOp = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
                        bufferedImage = cOp.filter(bufferedImage, null);
                        /* write the jpeg to a file */
                        File file = new File(resized);
                        FileOutputStream out = new FileOutputStream(file);
                        /* encodes image as a JPEG data stream */
                        JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
                        com.sun.image.codec.jpeg.JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bufferedImage);
                        // writeParam = new JPEGImageWriteParam(null);
                        // writeParam.setCompressionMode(JPEGImageWriteParam.MODE_EXPLICIT);
                        //writeParam.setProgressiveMode(JPEGImageWriteParam.MODE_DEFAULT);
                        param.setQuality(0.7f, true);
                        encoder.setJPEGEncodeParam(param);
                        encoder.encode(bufferedImage);
                        catch (Exception e)
                        System.out.println(e.getMessage());
              public static void main(String [] args)
                   long start = System.currentTimeMillis();
                   resize("beforeCompress90KB.jpg", "resized.jpg",200,150);
                   System.out.println("done in " + (System.currentTimeMillis() - start) + " ms");
    Please reply soon.I really need help
    Regards,
    Shveta

  • Using animated gif...

    I've encountered a problem in displaying animated gif using java Swing.
    For my program, I need to display 6 animated gif images. Sometimes I would get all those displayed, but sometimes only 1 or few are displayed.
    This problem troubles me until I found that it is the problem of animated gif I've used, because I have tried to replace the animated gif to static ones then every time the images are all displayed.
    I need a help urgently. Thanks a lot in advance.

    Hi
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    public class Dance extends JFrame 
    public Dance()  
         addWindowListener(new WindowAdapter()
        {     public void windowClosing(WindowEvent ev)
              {     dispose();
                   System.exit(0);}});
         getContentPane().setLayout(null);
         setBounds(10,10,400,300);
         JLabel j1 = new JLabel(new ImageIcon("cut1.gif"));
         j1.setBounds(10,30,40,40);
         getContentPane().add(j1);
         JLabel j2 = new JLabel(new ImageIcon("cut2.gif"));
         j2.setBounds(50,70,40,40);
         getContentPane().add(j2);
         JLabel j3 = new JLabel(new ImageIcon("cut3.gif"));
         j3.setBounds(90,110,40,40);
         getContentPane().add(j3);
         JLabel j4 = new JLabel(new ImageIcon("cut4.gif"));
         j4.setBounds(130,150,40,40);
         getContentPane().add(j4);
         setVisible(true);
    public static void main (String[] args)
         new Dance();
      Noah

  • Using animated gifs  in emails

    I've made an animated gif using flash an am trying to make it
    so the gif appears in my signature at the bottom of every email. I
    can place it in the signature but when I send the email the gif is
    static and doesn't move. Also I'm using a mac and when I recieve an
    animated gif in an email from a PC the gif is also static. I need
    to be able to send animated gifs in emails from PC and Mac using
    Mircosoft Outlook for PC and Entourage for MAC. Any help would be
    much appreciated.
    Cheers,

    this really has nothing to do with flash at all - you have no
    control over this as the recipient of
    your email may not be using an email client that supports
    animated gifs - does your gif work when
    viewed ina web page?
    you must realize there are a myriad ways people check email -
    sometimes via a browser, handheld
    device, email client software, etc...not all support animated
    gifs and the ones that do may have
    that option turned off by user.
    i would consult the support section of the email software
    your recipients use.
    --> **Adobe Certified Expert**
    --> www.mudbubble.com
    --> www.keyframer.com
    Luke H wrote:
    > I've made an animated gif using flash an am trying to
    make it so the gif
    > appears in my signature at the bottom of every email. I
    can place it in the
    > signature but when I send the email the gif is static
    and doesn't move. Also
    > I'm using a mac and when I recieve an animated gif in an
    email from a PC the
    > gif is also static. I need to be able to send animated
    gifs in emails from PC
    > and Mac using Mircosoft Outlook for PC and Entourage for
    MAC. Any help would be
    > much appreciated.
    >
    > Cheers,
    >
    >

Maybe you are looking for