I didn't spend much time making the program "good" from a UI sense, in fact I had to edit one line it and rerun for each image- but Processing is so quick that wasn't much of a burden. I would select each area in turn and tap the space bar when I was happy with the clipping region I had drawn.
The Processing code was:
PImage img;
String file = "45"; //change this for each image
void setup(){
size(1000,1000);
img = loadImage("orig/"+file+"_1000x1000.png");
}
float startX, startY;
void draw(){
image(img,0,0);
noFill();
rect(startX,startY,mouseX-startX,mouseY-startY);
}
void mousePressed(){
startX = mouseX;
startY = mouseY;
}
void keyPressed(){
float w = mouseX - startX;
if(w < 0) {
startX = mouseX;
w = abs(w);
}
float h = mouseY - startY;
if(h < 0) {
startY = mouseY;
h = abs(h);
}
int realX = round(startX * 7.008);
int realY = round(startY * 7.008);
int realW = round(w * 7.008);
int realH = round(h * 7.008);
int finalW = 1000;
if(realW == 0) realW = 1; //catch case if area not really drawn
float ratio = (float)finalW /(float) realW;
int finalH = round(ratio * realH);
println("convert orig/"+file+".png -crop "+realW+"x"+realH+"+"+realX+"+"+realY+
" -resize "+finalW+"x"+finalH+" out/"+file+"-"+".png");
flush();
}
The flush(); at the end didn't do what I wanted, which was to ensure Processing's output buffer showed the line immediately, but it worked well enough and wasn't worth fixing.
The ImageMagick command it output was:
convert origfile.png -crop WIDTHxHEIGHTxTOPxLEFT -resize WIDTHxHEIGHT outputfile.png
Another ImageMagick I had to lookup today is
convert file1.png file2.png file3.png +append outputfile.png
"+append" is pretty handy for making an "image sequence". I haven't experimented with what happens if the images are different heights, but it met my goal of making a simple "filmstrip" from the pages. (I'm going to use that as a simple thumbnail view.)
No comments:
Post a Comment