Browse code

fix collage.pike help example parameters

Dario Rodriguez authored on 13/06/2023 21:31:18
Showing 1 changed files
... ...
@@ -24,7 +24,7 @@ main(int argc, array(string) argv)
24 24
         Image.Image img,photo,frame;
25 25
         if(argc<5 || (argc>1 && argv[1]=="--help")) {
26 26
                 Stdio.werror("Syntax:  "+argv[0]+" <width_in_a4pages> <height_in_a4_pages> <resimage.png> <photodir> [<photodir2> [...]]\n");
27
-                Stdio.werror("Example: "+argv[0]+" 4 2 . result.png\n");
27
+                Stdio.werror("Example: "+argv[0]+" 4 2 result.png .\n");
28 28
                 return(1);
29 29
         }
30 30
         a4w=(int)argv[1];
Browse code

Initial commit

Dario Rodriguez authored on 28/10/2020 22:49:01
Showing 1 changed files
1 1
new file mode 100755
... ...
@@ -0,0 +1,76 @@
1
+#!/usr/bin/pike
2
+/*
3
+ * collage.pike
4
+ *
5
+ * Makes a poster-sized collage of all the photos on the specified directory
6
+ *
7
+ * History:
8
+ *      28/06/2019 Creation
9
+ *
10
+ * Author: Dario Rodriguez dario@softhome.net
11
+ * This program is distributed under the terms of the GNU GPL v2.1+
12
+ */
13
+
14
+int
15
+main(int argc, array(string) argv)
16
+{
17
+        int a4w,a4h;
18
+        string resfilename;
19
+        int imgw,imgh;
20
+        int dpi=300;
21
+        int pw,ph;
22
+        int framethickness;
23
+        int total;
24
+        Image.Image img,photo,frame;
25
+        if(argc<5 || (argc>1 && argv[1]=="--help")) {
26
+                Stdio.werror("Syntax:  "+argv[0]+" <width_in_a4pages> <height_in_a4_pages> <resimage.png> <photodir> [<photodir2> [...]]\n");
27
+                Stdio.werror("Example: "+argv[0]+" 4 2 . result.png\n");
28
+                return(1);
29
+        }
30
+        a4w=(int)argv[1];
31
+        a4h=(int)argv[2];
32
+        resfilename=argv[3];
33
+        // A4 is 8.27in � 11.69in (equivalent to 210mm � 297mm)
34
+        imgw=(a4w*dpi*827)/100;
35
+        imgh=(a4h*dpi*1169)/100;
36
+        // we want to fit approx. 4 photos in a a4, we calc the photo size
37
+        pw=dpi*827*(a4w+a4h)/(100*16);
38
+        ph=dpi*1169*(a4w+a4h)/(100*16);
39
+        framethickness=pw/20;
40
+        // resulting image
41
+        img=Image.Image(imgw,imgh);
42
+        // Put a nice bg
43
+// TODO
44
+        // add each photo
45
+        total=0;
46
+        foreach(argv[4..sizeof(argv)-1],string photodir) {
47
+                foreach(get_dir(photodir),string e) {
48
+                        if(sizeof(e)<4 || !(e[sizeof(e)-4..sizeof(e)]==".png" || e[sizeof(e)-4..sizeof(e)]==".jpg")) {
49
+                                write("* (Ignoring "+e+")\n");
50
+                                continue;
51
+                        }
52
+                        write("* Loading "+e+"...\n");
53
+                        photo=Image.load(photodir+"/"+e);
54
+                        write("* Resizing...\n");
55
+                        if(photo->xsize()>photo->ysize()) { /* landscape */
56
+                                photo=photo->scale(2*pw,2*photo->ysize()*pw/photo->xsize());
57
+                        } else { /* portrait */
58
+                                photo=photo->scale(2*photo->xsize()*ph/photo->ysize(),2*ph);
59
+                        }
60
+                        write("* Drawing frame...\n");
61
+                        frame=Image.Image(photo->xsize()+2*(2+framethickness),photo->ysize()+2*(2+framethickness),0,0,0);
62
+                        frame->box(2,2,frame->xsize()-1-2,frame->ysize()-1-2,255,255,255);
63
+                        frame->box(2*(1+framethickness),2*(1+framethickness),frame->xsize()-1-2*(1+framethickness),frame->ysize()-1-2*(1+framethickness),127,127,127);
64
+                        frame->paste(photo,2+framethickness,2+framethickness);
65
+                        // WARNING TODO: rotate, paste using layers
66
+                        frame=frame->scale(frame->xsize()/2,frame->ysize()/2);
67
+                        img->paste(frame,random(img->xsize()+photo->xsize())-photo->xsize()/2,random(img->ysize()+photo->ysize())-photo->ysize()/2);
68
+                        total++;
69
+                }
70
+        }
71
+        // write result
72
+        write("* Writing "+resfilename+"...\n");
73
+        Stdio.write_file(resfilename,Image.PNG.encode(img));
74
+        write("Composed "+total+" photos into "+resfilename+". Process finished.\n");
75
+
76
+}