-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathpsdTool.jsx
55 lines (54 loc) · 1.41 KB
/
psdTool.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
psdtool = {
depth : 0,
channels : 0,
width : 0,
height : 0,
mode : 0,
modeList : ["Bitmap","Grayscale","Indexed","RGB","CMYK","","","Multichannel","Duotone","Lab"],
sig: true,
getInfo : function(f){
f.encoding = 'BINARY';
var str = "";
var bds = [];
var sg = "";
if (f.open("r")){
for (var i=0;i<4;i++) sg += f.readch();
this.sig = (sg=="8BPS")? true : false;
f.seek(12);
this.channels = this.readUShort(f);
this.height = this.readULong(f);
this.width = this.readULong(f);
this.depth = this.readUShort(f);
this.mode = this.readUShort(f);
f.close();
}
return this;
},
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;
},
readULong: function(targetFile){
var result=0;
var a = 16777216;
for(var k=0;k<4;k++){
result += targetFile.readch().charCodeAt(0) * a;
a /= 256;
}
return result;
}
}
var val = psdtool.getInfo(File.openDialog ("select PSD File."));
if (val.sig){
var tx = "PSD File Information\n" + "width = " + val.width + " px\n";
tx += "height = " + val.height + " px\n";
tx += "mode = " + val.modeList[val.mode] + " \n";
tx += "depth = " + val.depth + " bits/channel\n"
+ "channels = " + val.channels + "(channels)";
alert (tx);
}
else alert("Not PSD File...");