JGif is a little gif editing library based on animated-gif-lib-for-java by rtyley.
- Implement this library in your project
- Create a GifImage object
- (Optional) Load a gif with GifImage#loadFrom(File)
- Edit your gif, add frames etc
- Save your gif to a file with GifImage#setOutputFile(File) and GifImage#save()
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.RealCerus</groupId>
<artifactId>JGif</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
public class GifTest {
public static void main(String[] args) {
GifImage image = new GifImage();
image.setOutputFile(new File("./output/output.gif"));
try {
image.loadFrom(new File("./my_gif.gif"));
} catch (FileNotFoundException e) {
e.printStackTrace();
return;
}
for(int i = 0; i < image.getFrames().size(); i++){
BufferedImage frame = image.getFrame(i);
Graphics graphics = frame.getGraphics();
graphics.setColor(Color.CYAN);
graphics.drawString("FRAME "+i, 50, 50);
graphics.dispose();
image.setFrame(i, frame);
}
image.reverseFrames();
image.save();
}
}