... | ... |
@@ -14,70 +14,70 @@ |
14 | 14 |
int |
15 | 15 |
main(int argc, array(string) argv) |
16 | 16 |
{ |
17 |
- int i; |
|
18 |
- string geom; |
|
19 |
- mapping imagemapping; |
|
20 |
- int xsize,ysize; |
|
17 |
+ int i; |
|
18 |
+ string geom; |
|
19 |
+ mapping imagemapping; |
|
20 |
+ int xsize,ysize; |
|
21 | 21 |
int xoff,yoff; |
22 |
- string destfilename; |
|
23 |
- Image.Image image,alpha; |
|
24 |
- array(Image.Layer) layers=({}); |
|
25 |
- Image.Layer l; |
|
22 |
+ string destfilename; |
|
23 |
+ Image.Image image,alpha; |
|
24 |
+ array(Image.Layer) layers=({}); |
|
25 |
+ Image.Layer l; |
|
26 | 26 |
if(argc<4 || (argc%2)!=0 || (argc>1 && argv[1]=="--help")) { |
27 | 27 |
Stdio.werror("Syntax: "+argv[0]+" <geom1> { <file1.png> | <htmlcolor1> } [<geom2> { <file2.png> | <htmlcolor2> } [...]] <outfile.png>\n"); |
28 | 28 |
Stdio.werror("Example: "+argv[0]+" 200x300+0+0 bg.png 150x0+25+25 image.png 100x1+0+0 \"#ff0000\" dest.png\n"); |
29 | 29 |
Stdio.werror("Example result: dest.png\n"); |
30 | 30 |
return(1); |
31 | 31 |
} |
32 |
- destfilename=argv[argc-1]; |
|
33 |
- write("* Loading images...\n"); |
|
34 |
- for(i=1;(i+1)<argc;i+=2) { |
|
35 |
- geom=argv[i]; |
|
36 |
- if(sizeof(argv[i+1])>1 && argv[i+1][0]=='#') { |
|
37 |
- string htmlcolor=argv[i+1]; |
|
38 |
- int r,g,b,a; |
|
39 |
- a=0; |
|
40 |
- htmlcolor-="#"; |
|
41 |
- sscanf(htmlcolor[0..1],"%x",r); |
|
42 |
- sscanf(htmlcolor[2..3],"%x",g); |
|
43 |
- sscanf(htmlcolor[4..5],"%x",b); |
|
44 |
- if(sizeof(htmlcolor)>6) |
|
45 |
- sscanf(htmlcolor[6..7],"%x",a); |
|
32 |
+ destfilename=argv[argc-1]; |
|
33 |
+ write("* Loading images...\n"); |
|
34 |
+ for(i=1;(i+1)<argc;i+=2) { |
|
35 |
+ geom=argv[i]; |
|
36 |
+ if(sizeof(argv[i+1])>1 && argv[i+1][0]=='#') { |
|
37 |
+ string htmlcolor=argv[i+1]; |
|
38 |
+ int r,g,b,a; |
|
39 |
+ a=0; |
|
40 |
+ htmlcolor-="#"; |
|
41 |
+ sscanf(htmlcolor[0..1],"%x",r); |
|
42 |
+ sscanf(htmlcolor[2..3],"%x",g); |
|
43 |
+ sscanf(htmlcolor[4..5],"%x",b); |
|
44 |
+ if(sizeof(htmlcolor)>6) |
|
45 |
+ sscanf(htmlcolor[6..7],"%x",a); |
|
46 | 46 |
write("r:"+r+" g:"+g+" b:"+b+" a:"+a+"\n"); |
47 |
- image=Image.Image(1,1,r,g,b); |
|
48 |
- imagemapping=([ "image":image, "alpha":Image.Image(1,1,255-a,255-a,255-a) ]); |
|
49 |
- } else { |
|
50 |
- imagemapping=Image._load(argv[i+1]); |
|
51 |
- } |
|
52 |
- xsize=ysize=xoff=yoff=0; |
|
53 |
- if(sizeof(geom/"x")>1) |
|
54 |
- xsize=(int) (geom/"x")[0]; |
|
55 |
- if(sizeof(geom/"x")>1) |
|
56 |
- ysize=(int) (((geom/"x")[1])/"+")[0]; |
|
57 |
- if(sizeof(geom/"+")>1) |
|
58 |
- xoff=(int) (geom/"+")[1]; |
|
59 |
- if(sizeof(geom/"+")>2) |
|
60 |
- yoff=(int) (geom/"+")[2]; |
|
61 |
- image=imagemapping["image"]; |
|
62 |
- alpha=imagemapping["alpha"]; |
|
63 |
- xsize=(xsize!=0)?xsize:(ysize==0)?image->xsize():ysize*image->xsize()/image->ysize(); |
|
64 |
- ysize=(ysize!=0)?ysize:(xsize==0)?image->ysize():xsize*image->ysize()/image->xsize(); |
|
65 |
- if(xsize!=image->xsize() || ysize!=image->ysize()) { |
|
66 |
- image=image->scale(xsize,ysize); |
|
67 |
- if(!intp(alpha)) |
|
68 |
- alpha=alpha->scale(xsize,ysize); |
|
69 |
- } |
|
70 |
- if(intp(alpha)) |
|
71 |
- alpha=Image.Image(xsize,ysize,255,255,255); |
|
72 |
- l=Image.Layer(image,alpha,"normal"); |
|
73 |
- l->set_offset(xoff,yoff); |
|
74 |
- layers+=({l}); |
|
75 |
- } |
|
76 |
- l=Image.lay(layers); |
|
77 |
- l->set_offset(0,0); |
|
78 |
- write("* Writing "+destfilename+"...\n"); |
|
79 |
- Stdio.write_file(destfilename,Image.PNG.encode(l->image(),(["alpha":l->alpha()]))); |
|
80 |
- write("* Finished successfully\n"); |
|
47 |
+ image=Image.Image(1,1,r,g,b); |
|
48 |
+ imagemapping=([ "image":image, "alpha":Image.Image(1,1,255-a,255-a,255-a) ]); |
|
49 |
+ } else { |
|
50 |
+ imagemapping=Image._load(argv[i+1]); |
|
51 |
+ } |
|
52 |
+ xsize=ysize=xoff=yoff=0; |
|
53 |
+ if(sizeof(geom/"x")>1) |
|
54 |
+ xsize=(int) (geom/"x")[0]; |
|
55 |
+ if(sizeof(geom/"x")>1) |
|
56 |
+ ysize=(int) (((geom/"x")[1])/"+")[0]; |
|
57 |
+ if(sizeof(geom/"+")>1) |
|
58 |
+ xoff=(int) (geom/"+")[1]; |
|
59 |
+ if(sizeof(geom/"+")>2) |
|
60 |
+ yoff=(int) (geom/"+")[2]; |
|
61 |
+ image=imagemapping["image"]; |
|
62 |
+ alpha=imagemapping["alpha"]; |
|
63 |
+ xsize=(xsize!=0)?xsize:(ysize==0)?image->xsize():ysize*image->xsize()/image->ysize(); |
|
64 |
+ ysize=(ysize!=0)?ysize:(xsize==0)?image->ysize():xsize*image->ysize()/image->xsize(); |
|
65 |
+ if(xsize!=image->xsize() || ysize!=image->ysize()) { |
|
66 |
+ image=image->scale(xsize,ysize); |
|
67 |
+ if(!intp(alpha)) |
|
68 |
+ alpha=alpha->scale(xsize,ysize); |
|
69 |
+ } |
|
70 |
+ if(intp(alpha)) |
|
71 |
+ alpha=Image.Image(xsize,ysize,255,255,255); |
|
72 |
+ l=Image.Layer(image,alpha,"normal"); |
|
73 |
+ l->set_offset(xoff,yoff); |
|
74 |
+ layers+=({l}); |
|
75 |
+ } |
|
76 |
+ l=Image.lay(layers); |
|
77 |
+ l->set_offset(0,0); |
|
78 |
+ write("* Writing "+destfilename+"...\n"); |
|
79 |
+ Stdio.write_file(destfilename,Image.PNG.encode(l->image(),(["alpha":l->alpha()]))); |
|
80 |
+ write("* Finished successfully\n"); |
|
81 | 81 |
return(0); |
82 | 82 |
} |
83 | 83 |
|
... | ... |
@@ -68,7 +68,7 @@ write("r:"+r+" g:"+g+" b:"+b+" a:"+a+"\n"); |
68 | 68 |
alpha=alpha->scale(xsize,ysize); |
69 | 69 |
} |
70 | 70 |
if(intp(alpha)) |
71 |
- alpha=Image.Image(xsize,ysize)->clear(0,0,0); |
|
71 |
+ alpha=Image.Image(xsize,ysize,255,255,255); |
|
72 | 72 |
l=Image.Layer(image,alpha,"normal"); |
73 | 73 |
l->set_offset(xoff,yoff); |
74 | 74 |
layers+=({l}); |
... | ... |
@@ -50,7 +50,8 @@ write("r:"+r+" g:"+g+" b:"+b+" a:"+a+"\n"); |
50 | 50 |
imagemapping=Image._load(argv[i+1]); |
51 | 51 |
} |
52 | 52 |
xsize=ysize=xoff=yoff=0; |
53 |
- xsize=(int) (geom/"x")[0]; |
|
53 |
+ if(sizeof(geom/"x")>1) |
|
54 |
+ xsize=(int) (geom/"x")[0]; |
|
54 | 55 |
if(sizeof(geom/"x")>1) |
55 | 56 |
ysize=(int) (((geom/"x")[1])/"+")[0]; |
56 | 57 |
if(sizeof(geom/"+")>1) |
1 | 1 |
new file mode 100755 |
... | ... |
@@ -0,0 +1,82 @@ |
1 |
+#!/usr/bin/pike |
|
2 |
+/* |
|
3 |
+ * paster.pike |
|
4 |
+ * |
|
5 |
+ * Resize a png into another png |
|
6 |
+ * |
|
7 |
+ * History: |
|
8 |
+ * 28/09/2020 Creation from resizer.pike |
|
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 i; |
|
18 |
+ string geom; |
|
19 |
+ mapping imagemapping; |
|
20 |
+ int xsize,ysize; |
|
21 |
+ int xoff,yoff; |
|
22 |
+ string destfilename; |
|
23 |
+ Image.Image image,alpha; |
|
24 |
+ array(Image.Layer) layers=({}); |
|
25 |
+ Image.Layer l; |
|
26 |
+ if(argc<4 || (argc%2)!=0 || (argc>1 && argv[1]=="--help")) { |
|
27 |
+ Stdio.werror("Syntax: "+argv[0]+" <geom1> { <file1.png> | <htmlcolor1> } [<geom2> { <file2.png> | <htmlcolor2> } [...]] <outfile.png>\n"); |
|
28 |
+ Stdio.werror("Example: "+argv[0]+" 200x300+0+0 bg.png 150x0+25+25 image.png 100x1+0+0 \"#ff0000\" dest.png\n"); |
|
29 |
+ Stdio.werror("Example result: dest.png\n"); |
|
30 |
+ return(1); |
|
31 |
+ } |
|
32 |
+ destfilename=argv[argc-1]; |
|
33 |
+ write("* Loading images...\n"); |
|
34 |
+ for(i=1;(i+1)<argc;i+=2) { |
|
35 |
+ geom=argv[i]; |
|
36 |
+ if(sizeof(argv[i+1])>1 && argv[i+1][0]=='#') { |
|
37 |
+ string htmlcolor=argv[i+1]; |
|
38 |
+ int r,g,b,a; |
|
39 |
+ a=0; |
|
40 |
+ htmlcolor-="#"; |
|
41 |
+ sscanf(htmlcolor[0..1],"%x",r); |
|
42 |
+ sscanf(htmlcolor[2..3],"%x",g); |
|
43 |
+ sscanf(htmlcolor[4..5],"%x",b); |
|
44 |
+ if(sizeof(htmlcolor)>6) |
|
45 |
+ sscanf(htmlcolor[6..7],"%x",a); |
|
46 |
+write("r:"+r+" g:"+g+" b:"+b+" a:"+a+"\n"); |
|
47 |
+ image=Image.Image(1,1,r,g,b); |
|
48 |
+ imagemapping=([ "image":image, "alpha":Image.Image(1,1,255-a,255-a,255-a) ]); |
|
49 |
+ } else { |
|
50 |
+ imagemapping=Image._load(argv[i+1]); |
|
51 |
+ } |
|
52 |
+ xsize=ysize=xoff=yoff=0; |
|
53 |
+ xsize=(int) (geom/"x")[0]; |
|
54 |
+ if(sizeof(geom/"x")>1) |
|
55 |
+ ysize=(int) (((geom/"x")[1])/"+")[0]; |
|
56 |
+ if(sizeof(geom/"+")>1) |
|
57 |
+ xoff=(int) (geom/"+")[1]; |
|
58 |
+ if(sizeof(geom/"+")>2) |
|
59 |
+ yoff=(int) (geom/"+")[2]; |
|
60 |
+ image=imagemapping["image"]; |
|
61 |
+ alpha=imagemapping["alpha"]; |
|
62 |
+ xsize=(xsize!=0)?xsize:(ysize==0)?image->xsize():ysize*image->xsize()/image->ysize(); |
|
63 |
+ ysize=(ysize!=0)?ysize:(xsize==0)?image->ysize():xsize*image->ysize()/image->xsize(); |
|
64 |
+ if(xsize!=image->xsize() || ysize!=image->ysize()) { |
|
65 |
+ image=image->scale(xsize,ysize); |
|
66 |
+ if(!intp(alpha)) |
|
67 |
+ alpha=alpha->scale(xsize,ysize); |
|
68 |
+ } |
|
69 |
+ if(intp(alpha)) |
|
70 |
+ alpha=Image.Image(xsize,ysize)->clear(0,0,0); |
|
71 |
+ l=Image.Layer(image,alpha,"normal"); |
|
72 |
+ l->set_offset(xoff,yoff); |
|
73 |
+ layers+=({l}); |
|
74 |
+ } |
|
75 |
+ l=Image.lay(layers); |
|
76 |
+ l->set_offset(0,0); |
|
77 |
+ write("* Writing "+destfilename+"...\n"); |
|
78 |
+ Stdio.write_file(destfilename,Image.PNG.encode(l->image(),(["alpha":l->alpha()]))); |
|
79 |
+ write("* Finished successfully\n"); |
|
80 |
+ return(0); |
|
81 |
+} |
|
82 |
+ |