#!/usr/bin/pike /* * collage.pike * * Makes a poster-sized collage of all the photos on the specified directory * * History: * 28/06/2019 Creation * * Author: Dario Rodriguez dario@softhome.net * This program is distributed under the terms of the GNU GPL v2.1+ */ int main(int argc, array(string) argv) { int a4w,a4h; string resfilename; int imgw,imgh; int dpi=300; int pw,ph; int framethickness; int total; Image.Image img,photo,frame; if(argc<5 || (argc>1 && argv[1]=="--help")) { Stdio.werror("Syntax: "+argv[0]+" [ [...]]\n"); Stdio.werror("Example: "+argv[0]+" 4 2 result.png .\n"); return(1); } a4w=(int)argv[1]; a4h=(int)argv[2]; resfilename=argv[3]; // A4 is 8.27in × 11.69in (equivalent to 210mm × 297mm) imgw=(a4w*dpi*827)/100; imgh=(a4h*dpi*1169)/100; // we want to fit approx. 4 photos in a a4, we calc the photo size pw=dpi*827*(a4w+a4h)/(100*16); ph=dpi*1169*(a4w+a4h)/(100*16); framethickness=pw/20; // resulting image img=Image.Image(imgw,imgh); // Put a nice bg // TODO // add each photo total=0; foreach(argv[4..sizeof(argv)-1],string photodir) { foreach(get_dir(photodir),string e) { if(sizeof(e)<4 || !(e[sizeof(e)-4..sizeof(e)]==".png" || e[sizeof(e)-4..sizeof(e)]==".jpg")) { write("* (Ignoring "+e+")\n"); continue; } write("* Loading "+e+"...\n"); photo=Image.load(photodir+"/"+e); write("* Resizing...\n"); if(photo->xsize()>photo->ysize()) { /* landscape */ photo=photo->scale(2*pw,2*photo->ysize()*pw/photo->xsize()); } else { /* portrait */ photo=photo->scale(2*photo->xsize()*ph/photo->ysize(),2*ph); } write("* Drawing frame...\n"); frame=Image.Image(photo->xsize()+2*(2+framethickness),photo->ysize()+2*(2+framethickness),0,0,0); frame->box(2,2,frame->xsize()-1-2,frame->ysize()-1-2,255,255,255); frame->box(2*(1+framethickness),2*(1+framethickness),frame->xsize()-1-2*(1+framethickness),frame->ysize()-1-2*(1+framethickness),127,127,127); frame->paste(photo,2+framethickness,2+framethickness); // WARNING TODO: rotate, paste using layers frame=frame->scale(frame->xsize()/2,frame->ysize()/2); img->paste(frame,random(img->xsize()+photo->xsize())-photo->xsize()/2,random(img->ysize()+photo->ysize())-photo->ysize()/2); total++; } } // write result write("* Writing "+resfilename+"...\n"); Stdio.write_file(resfilename,Image.PNG.encode(img)); write("Composed "+total+" photos into "+resfilename+". Process finished.\n"); }