-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathjpgTool.jsx
executable file
·55 lines (52 loc) · 1.24 KB
/
jpgTool.jsx
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
jpgtool = {
opt : "Baseline",
precision : 0,
components : 0,
width : 0,
height : 0,
getInfo : function(f){
f.encoding = 'BINARY';
var str = "";
var bds = [];
if (f.open("r")){
while(f.tell()<48000){
var d = jpgtool.readByte(f);
if (d==0xff){
d = jpgtool.readByte(f);
if (d==0xc2){
this.opt = "Progressive";
bds = jpgtool.getValue(f);
}
else if (d==0xc0){
bds = jpgtool.getValue(f);
}
}
}
f.close();
}
return this;
},
getValue : function(f){
var pos = jpgtool.readUShort(f) - 8;
this.precision = jpgtool.readByte(f);
this.height = jpgtool.readUShort(f);
this.width = jpgtool.readUShort (f);
this.components = jpgtool.readByte(f);
f.seek(pos, 1);
},
readByte : function(targetFile){
return targetFile.readch().charCodeAt(0);
},
readUShort : function(targetFile){
var result = targetFile.readch().charCodeAt(0) * 256;
result += targetFile.readch().charCodeAt(0);
return result;
}
}
var val = jpgtool.getInfo(File.openDialog ("select JPG File."));
var tx = val.opt + "\n"
+ "width = " + val.width + " px\n"
+ "height = " + val.height + " px\n"
+ "precision = " + val.precision + " bit\n"
+ "components = " + val.components + " (channel)";
alert (tx);