Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to create one Gif image from multiple images in Java? [closed]

Tags:

I am trying to set up a simple Java program that creates one single animated gif from multiple other images (jpg). Can anyone give me a hook on how to achieve this in Java? I already searched Google but couldn't find anything really helpful.

Thank you guys!

like image 498
user2399314 Avatar asked May 20 '13 12:05

user2399314


People also ask

How do I make multiple pictures into one GIF?

If you use Google Photos on Android (or iOS), you can make an animated GIF from a selection of your pictures. Just tap Library, then Utilities and Create New. Choose Animation, select the photos and tap Create.

How do you overlap a GIF?

Add a GIF over a still image. To make GIFs overlay images, the process is nearly the same. Just make sure the GIF has a transparent background so it can appear with the image behind it. Then add the still image to your Layers panel below the grouped GIF image, and it will appear behind the GIF.


1 Answers

Here you have an example of a class that creates an animated gif from different images:

Link

Edit: links seems to be dead. Anyway, just to be clear, this code was done by Elliot Kroo.

Edit 2: Thanks to @Marco13 for finding the WayBack Machine link. Updated the reference!

The class provides these methods:

class GifSequenceWriter {     public GifSequenceWriter(         ImageOutputStream outputStream,         int imageType,         int timeBetweenFramesMS,         boolean loopContinuously);      public void writeToSequence(RenderedImage img);      public void close(); } 

And also a little example:

public static void main(String[] args) throws Exception {   if (args.length > 1) {     // grab the output image type from the first image in the sequence     BufferedImage firstImage = ImageIO.read(new File(args[0]));      // create a new BufferedOutputStream with the last argument     ImageOutputStream output =        new FileImageOutputStream(new File(args[args.length - 1]));      // create a gif sequence with the type of the first image, 1 second     // between frames, which loops continuously     GifSequenceWriter writer =        new GifSequenceWriter(output, firstImage.getType(), 1, false);      // write out the first image to our sequence...     writer.writeToSequence(firstImage);     for(int i=1; i<args.length-1; i++) {       BufferedImage nextImage = ImageIO.read(new File(args[i]));       writer.writeToSequence(nextImage);     }      writer.close();     output.close();   } else {     System.out.println(       "Usage: java GifSequenceWriter [list of gif files] [output file]");   } } 

Props to Elliot Kroo for this code.

like image 153
aran Avatar answered Sep 28 '22 04:09

aran