... | ... |
@@ -6,7 +6,8 @@ |
6 | 6 |
* |
7 | 7 |
* History: |
8 | 8 |
* 1/07/2019 Creation |
9 |
- * 5/11/2019 Fix erroneous 1-pixel border around every tile |
|
9 |
+ * 5/11/2019 Fix erroneous 1-pixel border around every tile |
|
10 |
+ * 9/03/2023 Support transparency |
|
10 | 11 |
* |
11 | 12 |
* Author: Dario Rodriguez dario@softhome.net |
12 | 13 |
* This program is distributed under the terms of the GNU GPL v2.1+ |
... | ... |
@@ -20,7 +21,10 @@ main(int argc, array(string) argv) |
20 | 21 |
int px,py; |
21 | 22 |
string destfilename; |
22 | 23 |
int total; |
23 |
- Image.Image img,result; |
|
24 |
+ Image.Image image,alpha; |
|
25 |
+ Image.Layer l; |
|
26 |
+ mapping imagemapping; |
|
27 |
+ array(Image.Layer) layers=({}); |
|
24 | 28 |
if(argc<4 || (argc>1 && argv[1]=="--help")) { |
25 | 29 |
Stdio.werror("Syntax: "+argv[0]+" <width_in_tiles> <height_in_tiles> <file1.png> [<file2.png> [...]] <destfile.png>\n"); |
26 | 30 |
Stdio.werror("Example: "+argv[0]+" 3 2 file1.png file2.png file3.png file4.png file5.png file6.png dest.png\n"); |
... | ... |
@@ -34,19 +38,28 @@ main(int argc, array(string) argv) |
34 | 38 |
maxx=maxy=1; |
35 | 39 |
write("* Calculating tile size\n"); |
36 | 40 |
foreach(infiles, string f) { |
37 |
- img=Image.load(f); |
|
38 |
- if(img->xsize()>maxx) |
|
39 |
- maxx=img->xsize(); |
|
40 |
- if(img->ysize()>maxy) |
|
41 |
- maxy=img->ysize(); |
|
41 |
+ image=Image.load(f); |
|
42 |
+ if(image->xsize()>maxx) |
|
43 |
+ maxx=image->xsize(); |
|
44 |
+ if(image->ysize()>maxy) |
|
45 |
+ maxy=image->ysize(); |
|
42 | 46 |
} |
43 |
- result=Image.Image(maxx*a4w,maxy*a4h,255,255,255); |
|
47 |
+ image=Image.Image(maxx*a4w,maxy*a4h,255,255,255); |
|
48 |
+ alpha=Image.Image(maxx*a4w,maxy*a4h,0,0,0); |
|
49 |
+ l=Image.Layer(image,alpha,"normal"); |
|
50 |
+ l->set_offset(0,0); |
|
51 |
+ layers+=({l}); |
|
44 | 52 |
px=py=0; |
45 | 53 |
total=0; |
46 | 54 |
foreach(infiles, string f) { |
47 | 55 |
write("* Processing "+f+"...\n"); |
48 |
- img=Image.load(f); |
|
49 |
- result->paste(img,px*(maxx),py*(maxy)); |
|
56 |
+ imagemapping=Image._load(f); |
|
57 |
+ image=imagemapping["image"]; |
|
58 |
+ alpha=imagemapping["alpha"]; |
|
59 |
+ l=Image.Layer(image,alpha,"normal"); |
|
60 |
+ l->set_offset(px*(maxx),py*(maxy)); |
|
61 |
+ layers+=({l}); |
|
62 |
+ //result->paste(img,px*(maxx),py*(maxy)); |
|
50 | 63 |
px++; |
51 | 64 |
if(px>=a4w) { |
52 | 65 |
px=0; |
... | ... |
@@ -54,8 +67,10 @@ main(int argc, array(string) argv) |
54 | 67 |
} |
55 | 68 |
total++; |
56 | 69 |
} |
70 |
+ l=Image.lay(layers); |
|
71 |
+ l->set_offset(0,0); |
|
57 | 72 |
write("* Writing "+destfilename+"...\n"); |
58 |
- Stdio.write_file(destfilename,Image.PNG.encode(result)); |
|
73 |
+ Stdio.write_file(destfilename,Image.PNG.encode(l->image(),(["alpha":l->alpha()]))); |
|
59 | 74 |
write("tiled "+total+" images into "+destfilename+". Process finished.\n"); |
60 | 75 |
return(0); |
61 | 76 |
} |
... | ... |
@@ -6,7 +6,7 @@ |
6 | 6 |
* |
7 | 7 |
* History: |
8 | 8 |
* 1/07/2019 Creation |
9 |
- * 5/11/2019 Fix erroneous 1-pixel border around every tile |
|
9 |
+ * 5/11/2019 Fix erroneous 1-pixel border around every tile |
|
10 | 10 |
* |
11 | 11 |
* Author: Dario Rodriguez dario@softhome.net |
12 | 12 |
* This program is distributed under the terms of the GNU GPL v2.1+ |
... | ... |
@@ -16,7 +16,7 @@ int |
16 | 16 |
main(int argc, array(string) argv) |
17 | 17 |
{ |
18 | 18 |
int a4w,a4h; |
19 |
- int maxx,maxy; |
|
19 |
+ int maxx,maxy; |
|
20 | 20 |
int px,py; |
21 | 21 |
string destfilename; |
22 | 22 |
int total; |
... | ... |
@@ -30,30 +30,30 @@ main(int argc, array(string) argv) |
30 | 30 |
a4w=(int)argv[1]; |
31 | 31 |
a4h=(int)argv[2]; |
32 | 32 |
destfilename=argv[sizeof(argv)-1]; |
33 |
- array(string) infiles=argv[3..sizeof(argv)-2]; |
|
34 |
- maxx=maxy=1; |
|
35 |
- write("* Calculating tile size\n"); |
|
36 |
- foreach(infiles, string f) { |
|
37 |
- img=Image.load(f); |
|
38 |
- if(img->xsize()>maxx) |
|
39 |
- maxx=img->xsize(); |
|
40 |
- if(img->ysize()>maxy) |
|
41 |
- maxy=img->ysize(); |
|
42 |
- } |
|
43 |
- result=Image.Image(maxx*a4w,maxy*a4h,255,255,255); |
|
44 |
- px=py=0; |
|
45 |
- total=0; |
|
46 |
- foreach(infiles, string f) { |
|
47 |
- write("* Processing "+f+"...\n"); |
|
48 |
- img=Image.load(f); |
|
49 |
- result->paste(img,px*(maxx),py*(maxy)); |
|
50 |
- px++; |
|
51 |
- if(px>=a4w) { |
|
52 |
- px=0; |
|
53 |
- py++; |
|
54 |
- } |
|
55 |
- total++; |
|
56 |
- } |
|
33 |
+ array(string) infiles=argv[3..sizeof(argv)-2]; |
|
34 |
+ maxx=maxy=1; |
|
35 |
+ write("* Calculating tile size\n"); |
|
36 |
+ foreach(infiles, string f) { |
|
37 |
+ img=Image.load(f); |
|
38 |
+ if(img->xsize()>maxx) |
|
39 |
+ maxx=img->xsize(); |
|
40 |
+ if(img->ysize()>maxy) |
|
41 |
+ maxy=img->ysize(); |
|
42 |
+ } |
|
43 |
+ result=Image.Image(maxx*a4w,maxy*a4h,255,255,255); |
|
44 |
+ px=py=0; |
|
45 |
+ total=0; |
|
46 |
+ foreach(infiles, string f) { |
|
47 |
+ write("* Processing "+f+"...\n"); |
|
48 |
+ img=Image.load(f); |
|
49 |
+ result->paste(img,px*(maxx),py*(maxy)); |
|
50 |
+ px++; |
|
51 |
+ if(px>=a4w) { |
|
52 |
+ px=0; |
|
53 |
+ py++; |
|
54 |
+ } |
|
55 |
+ total++; |
|
56 |
+ } |
|
57 | 57 |
write("* Writing "+destfilename+"...\n"); |
58 | 58 |
Stdio.write_file(destfilename,Image.PNG.encode(result)); |
59 | 59 |
write("tiled "+total+" images into "+destfilename+". Process finished.\n"); |
1 | 1 |
new file mode 100755 |
... | ... |
@@ -0,0 +1,62 @@ |
1 |
+#!/usr/bin/pike |
|
2 |
+/* |
|
3 |
+ * tiler.pike |
|
4 |
+ * |
|
5 |
+ * Tiles NxM different pngs into a single png |
|
6 |
+ * |
|
7 |
+ * History: |
|
8 |
+ * 1/07/2019 Creation |
|
9 |
+ * 5/11/2019 Fix erroneous 1-pixel border around every tile |
|
10 |
+ * |
|
11 |
+ * Author: Dario Rodriguez dario@softhome.net |
|
12 |
+ * This program is distributed under the terms of the GNU GPL v2.1+ |
|
13 |
+ */ |
|
14 |
+ |
|
15 |
+int |
|
16 |
+main(int argc, array(string) argv) |
|
17 |
+{ |
|
18 |
+ int a4w,a4h; |
|
19 |
+ int maxx,maxy; |
|
20 |
+ int px,py; |
|
21 |
+ string destfilename; |
|
22 |
+ int total; |
|
23 |
+ Image.Image img,result; |
|
24 |
+ if(argc<4 || (argc>1 && argv[1]=="--help")) { |
|
25 |
+ Stdio.werror("Syntax: "+argv[0]+" <width_in_tiles> <height_in_tiles> <file1.png> [<file2.png> [...]] <destfile.png>\n"); |
|
26 |
+ Stdio.werror("Example: "+argv[0]+" 3 2 file1.png file2.png file3.png file4.png file5.png file6.png dest.png\n"); |
|
27 |
+ Stdio.werror("Example result: dest.png\n"); |
|
28 |
+ return(1); |
|
29 |
+ } |
|
30 |
+ a4w=(int)argv[1]; |
|
31 |
+ a4h=(int)argv[2]; |
|
32 |
+ destfilename=argv[sizeof(argv)-1]; |
|
33 |
+ array(string) infiles=argv[3..sizeof(argv)-2]; |
|
34 |
+ maxx=maxy=1; |
|
35 |
+ write("* Calculating tile size\n"); |
|
36 |
+ foreach(infiles, string f) { |
|
37 |
+ img=Image.load(f); |
|
38 |
+ if(img->xsize()>maxx) |
|
39 |
+ maxx=img->xsize(); |
|
40 |
+ if(img->ysize()>maxy) |
|
41 |
+ maxy=img->ysize(); |
|
42 |
+ } |
|
43 |
+ result=Image.Image(maxx*a4w,maxy*a4h,255,255,255); |
|
44 |
+ px=py=0; |
|
45 |
+ total=0; |
|
46 |
+ foreach(infiles, string f) { |
|
47 |
+ write("* Processing "+f+"...\n"); |
|
48 |
+ img=Image.load(f); |
|
49 |
+ result->paste(img,px*(maxx),py*(maxy)); |
|
50 |
+ px++; |
|
51 |
+ if(px>=a4w) { |
|
52 |
+ px=0; |
|
53 |
+ py++; |
|
54 |
+ } |
|
55 |
+ total++; |
|
56 |
+ } |
|
57 |
+ write("* Writing "+destfilename+"...\n"); |
|
58 |
+ Stdio.write_file(destfilename,Image.PNG.encode(result)); |
|
59 |
+ write("tiled "+total+" images into "+destfilename+". Process finished.\n"); |
|
60 |
+ return(0); |
|
61 |
+} |
|
62 |
+ |