Image mirror

Mirrored images

I made a program for @bitmapchaos that takes an image and creates two mirrored image files (images are mirrored across the horizontal center of the original image) in the same folder. You can download a java app here, and the Processing source code is in the full post.

Processing source code:
[sourcecode]PImage img0;
PImage img1;
PImage img2;
String fileLocation, fileName, fileType;
String[] slashSplit = {};
String[] dotSplit = {};

int scaledImageSize = int(screen.height/2);
int imageWidth, imageHeight;

void setup() {
fileLocation = selectInput();
slashSplit = split(fileLocation,’/’);

fileName = slashSplit[slashSplit.length-1];
dotSplit = split(fileName, ‘.’);
fileType = dotSplit[dotSplit.length-1];
fileName = dotSplit[0];

img0 = loadImage(fileLocation);
img1 = loadImage(fileLocation);
img2 = loadImage(fileLocation);

img1.loadPixels();
img2.loadPixels();

for (int y = 0; y < img1.height; y++) { for (int x = 0; x < img1.width/2; x++) { img1.pixels[y*img1.width+x] = img1.pixels[(y+1)*img1.width-x-1]; } } img1.updatePixels(); for (int y = 0; y < img2.height; y++) { for (int x = 0; x < img2.width/2; x++) { img2.pixels[(y+1)*img2.width-x-1] = img2.pixels[y*img2.width+x]; } } img2.updatePixels(); img1.save(fileName+"_1."+fileType); img2.save(fileName+"_2."+fileType); if (img0.height > img0.width) {
imageWidth = int(map(img0.width, 0, img0.height, 0, scaledImageSize));
imageHeight = scaledImageSize;
}
else {
imageHeight = int(map(img0.height, 0, img0.width, 0, scaledImageSize));
imageWidth = scaledImageSize;
}

size(imageWidth*2+1,imageHeight*2+1);
noLoop();
}

void draw() {
image(img0,imageWidth/2,0,imageWidth,imageHeight);
image(img1,0,imageHeight+1,imageWidth,imageHeight);
image(img2,imageWidth+1,imageHeight+1,imageWidth,imageHeight);
}[/sourcecode]

Tagged with:
 

Comments are closed.