Skip to content

Instantly share code, notes, and snippets.

@taboularasa
Created March 23, 2009 01:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save taboularasa/83375 to your computer and use it in GitHub Desktop.
Save taboularasa/83375 to your computer and use it in GitHub Desktop.
Open the last saved jpeg image Save it as a new jpeg image with slightly more compression Repeat 600 times
import com.sun.image.codec.jpeg.*;
PImage img;
int numberOfFrames = 600;
void setup()
{
size(1024,768);
}
void draw()
{
for(int i =1; i < numberOfFrames ; i++)
{
PImage reference = loadImage("sky"+(i-1)+".jpg");
image(reference,0,0);
BufferedImage img=new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
loadPixels();
img.setRGB(0, 0, width, height, g.pixels, 0, width);
try{
ByteArrayOutputStream out = new ByteArrayOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam p = encoder.getDefaultJPEGEncodeParam(img);
float q = map(i,0,numberOfFrames,1,0);
p.setQuality(q,true);
encoder.setJPEGEncodeParam(p);
encoder.encode(img);
File file = new File(savePath("data/sky"+i+".jpg"));
FileOutputStream fo = new FileOutputStream(file);
out.writeTo(fo);
}
catch(FileNotFoundException e){
System.out.println(e);
}
catch(IOException ioe){
System.out.println(ioe);
}
}
exit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment