Skip to content

Instantly share code, notes, and snippets.

@bmoren
Last active August 29, 2015 14:27
Show Gist options
  • Save bmoren/30fdfd853a45a4a1e273 to your computer and use it in GitHub Desktop.
Save bmoren/30fdfd853a45a4a1e273 to your computer and use it in GitHub Desktop.
create GIF animations from a folder of images at any length of frames
import gifAnimation.*;
GifMaker gifExport;
static int FRAME_RATE = 30;
//Select a folder to process:, It must contain images with filename '1.jpg, 2.jpg,3.jpg,etc.
String PATH = "/Users/bmoren/Desktop/GifFrames/"; //make sure there is a "/" at the end of the filepath
//how many files to process?
int IMAGE_NB = 1; // first in sequence (or where to start?)
int TOTAL = 1644 ; //how many in forlder (or to go up to?)
public void setup() {
size(32, 32);
frameRate(FRAME_RATE);
gifExport = new GifMaker(this, "export.gif");
// make it a looping animation
gifExport.setRepeat(0);
/* make white the transparent color. EVERY white pixel in the animation will be transparent.
* GIF doesn't have alpha like processing. a pixel can only be totally transparent or totally opaque.
*
* set the processing background and the transparent gif color to the same value as the gifs destination background color
* (e.g. the website bg-color). Like this you can have the antialiasing from processing in the gif.*/
//gifExport.setTransparent(255, 255, 255);
}
void draw() {
background(255);
if (IMAGE_NB < TOTAL) {
image(loadImage(PATH + IMAGE_NB++ + ".jpg"), 0, 0);
gifExport.setDelay(1000/FRAME_RATE);
gifExport.addFrame();
} else {
image(loadImage(PATH + IMAGE_NB++ + ".jpg"), 0, 0);
gifExport.setDelay(1000/FRAME_RATE);
gifExport.addFrame();
gifExport.finish();
println("Finished! Exporting...");
exit();
}
}
@bmoren
Copy link
Author

bmoren commented Aug 20, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment