Skip to content

Instantly share code, notes, and snippets.

@bmoren
Created January 5, 2015 16:12
Show Gist options
  • Save bmoren/2a1c10f9eb07cebd586c to your computer and use it in GitHub Desktop.
Save bmoren/2a1c10f9eb07cebd586c to your computer and use it in GitHub Desktop.
Image Layer #2
String PATH = "/Users/bmoren/Desktop/Aspens_test/JPG/";
int IMAGE_NB = 0001; // first in sequence
int imageAlpha = 100;
PImage composition;
PImage workingImage;
boolean firstImage = true;
void setup()
{
size(5184,3456);
background(255);
//tint(255,10); // this setting will stick
}
void draw() {
String fileName = PATH + nf(IMAGE_NB++, 4) + ".jpg";
if(firstImage) {
firstImage = false;
composition = loadImage(fileName);
AddTransparency(composition,imageAlpha);
} else {
workingImage = loadImage(fileName);
AddTransparency(workingImage,imageAlpha);
composition.blend(workingImage, 0, 0, workingImage.width,
workingImage.height, 0, 0, workingImage.width, workingImage.height,
BLEND);
}
image(composition,0,0);
}
void keyPressed() {
// spacebar to save the current image
if (key == ' ') saveFrame("img_" + IMAGE_NB + ".jpg");
print("exported");
}
void AddTransparency(PImage theImage, int transparency)
{
// shift transparency (0-255) into the right location in the packed int
transparency <<= 24;
transparency |= 0x00FFFFFF; // mask everything else out
for (int i = 0; i < theImage.width * theImage.height; i++) {
theImage.pixels[i] &= transparency; // mask the pixel
}
theImage.updatePixels(); // update the pixels
theImage.format = ARGB; // it's got an alpha layer now
saveFrame("img_" + IMAGE_NB + ".jpg");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment