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.

Similar Messages

  • 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.

  • 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.

  • 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.
    >

  • 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

  • Animated gif resizing problem

    Im trying to achieve the following: showing an animated gif that resizes to fill the area of a canvas. I tried the easy way: adding a label and setting the icon for that label, but when trying to resize the image it doesnt show (see code below). Is there any particular way of resizing an animated gif? can the labe-icon approach be used with animated gif that must be resized?
    Thanks a lot in advance.
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Image;
    import javax.swing.ImageIcon;
    public class TestFrame extends javax.swing.JFrame {
    /** Creates new form TestFrame */
    public TestFrame() {
    initComponents();
    Image image = this.getToolkit().getImage("C:\\multivideo\\img\\39.gif");
    Dimension dim = jLabel1.getPreferredSize();
    image = image.getScaledInstance(dim.width, dim.height, Image.SCALE_SMOOTH);
    ImageIcon i = new ImageIcon(image);
    jLabel1.setIcon(i);
    jLabel1.setBackground(Color.BLUE);
    pack();
    /** This method is called from within the constructor to
    * initialize the form.
    private void initComponents()
    jLabel1 = new javax.swing.JLabel();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jLabel1.setIcon(new javax.swing.ImageIcon("C:\\multivideo\\img\\40.gif"));
    jLabel1.setMaximumSize(new java.awt.Dimension(1436, 86));
    jLabel1.setMinimumSize(new java.awt.Dimension(1436, 86));
    jLabel1.setPreferredSize(new java.awt.Dimension(1436, 86));
    getContentPane().add(jLabel1, java.awt.BorderLayout.CENTER);
    pack();
    * @param args the command line arguments
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new TestFrame().setVisible(true);
    private javax.swing.JLabel jLabel1;
    }

    I don't think getScaledInstance is smart enough to return a scaled image.
    You could try doing your own scaling:
    import java.awt.*;
    import java.awt.geom.*;
    import java.net.*;
    import javax.swing.*;
    public class Animated extends JComponent {
        private Image image;
        private double scale;
        public Animated(URL url, double scale) {
            image = new ImageIcon(url).getImage();
            this.scale = scale;
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Insets insets = getInsets();
            Graphics2D g2 = (Graphics2D) g.create();
            g2.translate(insets.left, insets.top);
            g2.scale(scale, scale);
            g2.drawImage(image, 0, 0, this);
            g2.dispose();
        public Dimension getPreferredSize() {
            Insets insets = getInsets();
            int w = insets.left + insets.right + (int)(scale*image.getWidth(null));
            int h = insets.top + insets.bottom + (int)(scale*image.getHeight(null));
            return new Dimension(w,h);
        public static void main(String[] args) throws MalformedURLException {
            URL url = new URL("http://members.aol.com/royalef/sunglass.gif");
            final JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(new Animated(url, 2), BorderLayout.NORTH);
            f.getContentPane().add(new Animated(url, 1), BorderLayout.SOUTH);
            f.pack();
            SwingUtilities.invokeLater(new Runnable(){
                public void run() {
                    f.setLocationRelativeTo(null);
                    f.setVisible(true);
    }Or you could explicitly extract the images from the animated gif and
    resize them individually. The sample code here does the extraction:
    http://forum.java.sun.com/thread.jspa?forumID=20&threadID=500348

  • Loss transparency in an animated GIF image when resizing

    Hi Friends,
    I have to write a program to resize GIF, JPEG , and PNG images. I wrote and it works but when i resize a GIF file it loses its transparency and give a black color for transparent area.
    I used a GifDecoder found at www.fmsware.com/stuff/GifDecoder.java
    and a gif encoder found at jmge.net/java/gifenc/Gif89a090b.zip.
    i don't know where the problem is .
    i have some small problems in here.
    How can i preserve the transparency of GIF image?
    How can i set a transparent color in Graphic2D object? smtimes it may help me. or error may be in the encoder.
    Help me guys.
    Thanks and regards,
    Manjula

    Java comes with gif encoder/decoders.
    Gifs are indexed images. This means that, for example, each pixel is an 8 bit value that is used to look up the correct 24 bit value in the index table. Gifs handle transparency by allowing one particular pixel value to be nominated as transparent.
    If you just rescale the image then you will likely cause pixels with the magic "transparent" value to change their value and become normal pixels. Alternately pixels that are not transparent may have their values changed such that they are transparent.
    Possibly the easyist solution to to force the image into a full RGBA image. Scale this then perform post processing on the image. I.e convert it back into an indexed image, looking at the values of the alpha channel (prior to making it indexed and if they are high enough then modify the corresponding pixel in the indexed image to have the magic transparent value. Then use Metadata passed to your Image writer to indicate which value is transparent.
    matfud

  • Animated GIF Export issues

    I have a simple Flash animation which I'd like to be made
    into a transparent GIF.
    When I do the GIF export, only the first frame of my
    movieclips (which are placed in the main timeline) get rendered. It
    seems like Flash only records the main timeline preview output into
    the GIF file, and does not play movieclip objects. You would expect
    the GIF recording to be of the same preview as when you hit
    ctrl+enter (essentially final playback).
    Because of this, the GIF export is pointless. The only way to
    use it is to have all your animations occur in the main timeline,
    and not within movieclips. It doesn't work for me (and for most
    people?), because I need to easily scale my animations, which is
    doable by just resizing a movieclip.
    Is there a way around this in Flash? Am I missing something?
    I've had to use a 3rd-party tool (Magic SWF2GIF) to do the
    GIF recording.
    My other issue is Flash cannot export transparent GIF's it
    seems. Because of this, I have to rely on more 3rd-party GIF tools,
    most of which are rubbish.
    In the end, I've had to take snap shots of every individual
    frame and edit each frame as individual files in Photoshop to do
    all the cropping and transparency just right. Real pain when you
    are talking 50 frames, and having to do multiple animations.
    Is there a way to export transparent GIF's in Flash?
    Seems kind of dumb that I have all this high-end software and
    loads of tools... and I still have to edit things frame by
    frame.

    Thank you for your reply!
    I check exported GIFs in various browsers and XnView viewer.
    It's definitely not a preview  issue - i have 32Gb of RAM and Nvidia Quadro 4000 GPU on my system.
    I believe the issue is with transparency, because i'm able to export GIFs with solid background just fine
    GIF export dialogue window has 'Transparency' checkbox, so it looks like it should be possible to export an animated GIF with transparent background, but for some reason i'm getting all frames at the same time
    thank you

  • Animated gif only plays one time??

    An animated gif created in Photoshop and exported with 'loop forever' output only loops once on my home page. I have not resized, cropped it or added any effects but as it plays once Muse can't have rasterized it.
    I am using adobe muse cc 7.1 build 329, OSX 10.9
    the lilly in the top left gif image should animate continuously. - jimmymcgilchrist.comhttp://www.jimmymcgilchrist.com/index.html
    any assistance appreciated.
    Jimmy

    Hi DrStrik9,
    Thanks, I just tried it directly in the browser and it works fine. When previewing in the finder window on my desktop it works fine as well.
    I have had animated gifs working fine previously on the same muse site as a browser fill and as buttons.
    Nothing has changed about the way I make the animation but these are some variables that have changed:
    - update Operating System from OSX 10.8 to 10.9
    - udate to current muse version
    - switch from Godaddy - wordpress hosting to Adobe Business Catalyst
    - upload via 'publish' within muse rather than via 'upload to FTP host' within muse.
    Thanks,
    Jimmy

  • Animated .GIF in Fireworks

    Hello everyone,
    I'm trying to train myself with Fireworks so please bare with me.  I'm attempting to make an animated .gif and my question is: Is there a way to insert each image to automatically fit the canvas (100 pixels X 100 pixels)?  Currently I have to resize each different image to the canvas size in each State and it is very time consuming as there are approximately 90 different images (frames from a video).  Furthermore, is there a way I can take all 90 images and have them inserted and sized into 90 different States automatically?  Thanks for the help in advance!

    A 90 frame animation is pretty hefty. You can try a batch processing operation to scale the images first, but that would assume the images are already square.
    Once you have the images, though, you can choose File > Open, select all the graphics and choose the Open as Animation option in the Open File dialog box. That will put one image on each frame.
    Jim Babbage

  • Animated gif image

    Hi
    I like to create an animated gif image from a given set of images with java. I like to do this with the given set of java api as I do not want to use a commercial graphics library. Can anyone provide me with a sample example.
    Thanks

    Hi
    I like to resize a gif image. Currently i am using the following code but the resized image is not smooth.
    public BufferedImage resizeImage(BufferedImage img, int newW, int newH)
              int w = img.getWidth();
              int h = img.getHeight();
              BufferedImage dimg = new BufferedImage(newW, newH, img.getType());
              Graphics2D g = dimg.createGraphics();
              g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
              g.drawImage(img, 0, 0, newW, newH, 0, 0, w, h, null);
              g.dispose();
              return dimg;
    Is there a way to resize a gif image in a smooth way as the example given in the gif4j library
    Thanks

  • Fuzzy Edges on Animated Gif

    I created a very simple animation in Fireworks that loops to
    a closed circle. It's pixelated around the edges and also has a
    thin, pixilated white line around it. Does anyone know how to get
    rid of this? I used "index transparency" on my export settings and
    left the rest at default.

    Just came across this same issue in CS5.  Sometimes when you resize an image using the "Image size" function, Fireworks does not properly scale either the width or the height to the closest absolute pixel.  This creates a sub pixel which becomes apparent with exporting GIFs.  You can see the scaling issue if you throw  a 1 pixel solid hard edge border around your image: if you see a transparent gap on the outside of the border then you've got the issue & it's this that causes the GIF image to go blurry when exported.   The fix is to crop the image changing the canvas size to "absolutely" crop the image.
    Generally the animated Fireworks GIFs exports are a buggy part of an otherwise great web graphic design tool:
    both palettes not correctly mapping colour
    frame times can go heywire in complex documents with multiple pages and states
    the export of an animated gif with a document with multiple pages and states can generate redundant files.

  • Exporting flash video made with swift 3d to animated gif help

    I know there is a new grounds link about setting your publishing settings to get animated gifs to work with flash.
    I am using CS4 and when I go to publish the gif works in the html document. But when I export to an animated gif it is still a still picture.
    I have also tried to export to a quicktime file and it's is a still picture there too and distorted.
    Can anyone help me out? Should exporting to png or gif sequence work as well?

    turns out the swift 3d tutorial has you put the animation in a single keyframe within layer one.
    so only one frame is shown or created. there go it stays static
    now if someone could help me wiht resizing a gif for fireworks i would be the happest person

Maybe you are looking for