File size: 4,550 Bytes
38c9082
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<html><body>
<style>body {background-color: black; color:#fff;}

img { -webkit-mask: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAQMAAABJtOi3AAAABlBMVEUAAAD///+l2Z/dAAAAAXRSTlOArV5bRgAAABNJREFUCNdj+P+fgYGaBAN1TQQA7b0/wa0PmxMAAAAASUVORK5CYII=); 

position: absolute; top: 0; right: 0;}

</style>
<div id='wk'></div><br>
D:\wxn\bjpeg	<textarea id='bn1' rows="10" cols="100"></textarea>
</body>
<script>



const go = {

	set x16(v) {

	var klm=v&0xfffffff0;

	//

	console.log(klm+'\nppx '+(klm+16));

	},

	set red(v) {

	document.body.style.backgroundColor='red';

	}

}



function ret0(ev) {ev.preventDefault(); return false;}

function clkcpy() {navigator.clipboard.writeText(txta.value); return false;}

function drgclk(){curctrl=this;}

var wk=document.getElementById('wk');

var txta=document.getElementById('bn1');

var ldn=[];

var dcot=0;

var curctrl=null;

var kycmd=function(e) {

var ekeyCode=e.keyCode;

switch(ekeyCode)

{

	case 90:

		zundo();

		return;

	case 13:

		finalcalc();

		return;

	case 97:

		curctrl.ofx-=16;

	case 98:

		curctrl.ofy+=16;

		break;

	case 99:

		curctrl.ofy+=16;

	case 102:

		curctrl.ofx+=16;

		break;

	case 105:

		curctrl.ofx+=16;

	case 104:

		curctrl.ofy-=16;

		break;

	case 103:

		curctrl.ofy-=16;

	case 100:

		curctrl.ofx-=16;

		break;

	

	default:

		return;

	



}

curctrl.style.left=curctrl.ofx;

curctrl.style.top=curctrl.ofy;

}



function apok()

{

	ldn[this.yid]= this;

	dcot--;

	if(dcot==0)

	{

		var cot=ldn.length;

		var ele=ldn[0];

		var mvt=ele.naturalHeight&0xfffffff0;

		wk.style.width=ele.naturalWidth;

		ele.style.top=0;

		ele.style.left=0;

		for(var i=1;i<cot;i++)

		{

			var ele=ldn[i];

			ele.style.top=mvt;

			ele.ofy=mvt;

			ele.ofy_lzt=mvt;

			ele.style.left=0;

			mvt+=ele.naturalHeight&0xfffffff0;

		}

		

		wk.style.height=mvt;

		document.onkeydown=kycmd;

	}

}



function zundo()

{

	curctrl.ofx=curctrl.ofx_lzt;

	curctrl.style.left=curctrl.ofx;

	curctrl.ofy=curctrl.ofy_lzt;

	curctrl.style.top=curctrl.ofy;

	return;

}



function drggend(ev)

{

	const rect = ev.target.getBoundingClientRect();

	//console.log(ev.clientX+', '+rect.x);

	//console.log(ev.clientY+', '+rect.y);



	var ofx=(ev.clientX-rect.x)&0xfffffff0;

	var ofy=(rect.y)&0xfffffff0;

	curctrl=this;

	this.ofx_lzt=this.ofx;

	this.ofx+=ofx;

	this.style.left=this.ofx;

	this.ofy_lzt=this.ofy;

	this.ofy-=ofy;

	this.style.top=this.ofy;

}



function mkimg(fna)

{

var bsimg=document.createElement('img');

bsimg.src=fna;

bsimg.onload=apok;

bsimg.draggable=true;

bsimg.onclick=drgclk;

bsimg.ondragend=drggend;

bsimg.ofx=0;

bsimg.ofy=0;

bsimg.ofx_lzt=0;

bsimg.ofy_lzt=0;

wk.appendChild(bsimg);

return bsimg;

}







function ldimg()

{	

	var origfnaz=txta.value.replaceAll('"','');

	var fnaz=origfnaz.replaceAll('\\','/').split('\n');

	origfnaz=origfnaz.split('\n');

	origna=[];

	ldn=[];

	var cot=fnaz.length;

	for(var i=0;i<cot;i++)

	{

		var ff=fnaz[i];

		if(ff.length>2){ldn.push('file:///'+ff); origna.push(origfnaz[i]);}

	}

	cot=ldn.length;

	dcot=cot;

	for(var i=0;i<cot;i++)

	{

		var ymg=mkimg(ldn[i]);

		ymg.yid=i;

	}

	txta.oncontextmenu=clkcpy;

	txta.onclick=clkcpy;

	return false;

}



txta.oncontextmenu=ldimg;



function swapodr(n1,n2)

{

	var tmp=ldn[n1];

	ldn[n1]=ldn[n2];

	ldn[n2]=tmp;

	tmp=origna[n1];

	origna[n1]=origna[n2];

	origna[n2]=tmp;

}



function finalcalc()

{

	var vtop=0xfffff;

	var vbot=0;

	var vlft=0xfffff;

	var vrgt=0;

	var cot=ldn.length;

	for(var i=0;i<cot;i++)

	{

		var ele=ldn[i];

		var ofy=ele.ofy;

		if(ofy<vtop){vtop=ofy;}

		ofy+=ele.naturalHeight;

		if(ofy>vbot){vbot=ofy;}

		ofy=ele.ofx;

		if(ofy<vlft){vlft=ofy;}

		ofy+=ele.naturalWidth;

		if(ofy>vrgt){vrgt=ofy;}

	}

	

	wk.style.height=vbot;

	vbot-=vtop;

	vrgt-=vlft;



	var yfo=new Array(cot);

	for(var i=0;i<cot;i++){yfo[i]=[ldn[i].ofx-vlft,ldn[i].ofy-vtop];}

	var txtout=['jpegtran.exe -crop '+vrgt+'x'+vbot+'+'+yfo[0][0]+'+'+yfo[0][1]+' -outfile tmp.jpg "'+origna[0]+'"'];

	for(var i=1;i<cot;i++){

		if(origna[i].endsWith('.png')) {txtout.push('--PNG--\npause');}

		else {

			txtout.push('jpegtran2.exe -drop +'+yfo[i][0]+'+'+yfo[i][1]+' "'+origna[i]+'" -outfile tmp0.jpg tmp.jpg');

			txtout.push('del tmp.jpg');

			txtout.push('ren tmp0.jpg tmp.jpg');

		}

	}

	txtout[txtout.length - 1]='jpegtran.exe -optimize -copy none -outfile out.jpg tmp0.jpg\npause\ndel tmp0.jpg';

	

	txta.rows=txtout.length+10;

	txta.value=txtout.join('\n');

	

}





</script></html>