... | ... |
@@ -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 |
|