复制内容到剪贴板
代码:
#target photoshop
app.bringToFront();
// 带自动判断横竖的统一宽高操作。默认是直接保存关闭,原文件要注意备份! v1.2 - 2008.2.27
// 原发:bbs.blueidea.com - Photoshop版
var PRESOLUTION = 72;
app.preferences.rulerUnits = Units.PIXELS;
var title="批量尺寸调整 v1.2 - "
res ="dialog { \
text:'"+title+"直接保存并关闭',\
group: Group{orientation: 'column',alignChildren:'left',\
top:StaticText{text:'默认为直接覆盖保存 - 请注意选择或做好备份'},\
timeline:Progressbar{bounds:[0,0,300,10] , minvalue:0,maxvalue:100}\
corrdination: Panel { orientation: 'row', \
text: '需要尺寸', \
x: Group { orientation: 'row', \
s: StaticText { text:'宽:' }, \
e: EditText { preferredSize: [50, 20] } ,\
p: StaticText { text:'px' }, \
}, \
y: Group { orientation: 'row', \
s: StaticText { text:'高:' }, \
e: EditText { preferredSize: [50, 20] }, \
p: StaticText { text:'px' }, \
} ,\
}, \
a:Group{ orientation: 'row', \
c: Checkbox { text:' 保持原图宽高比,新尺寸仅作外框限定',helpTip:'原图比例不变,调整后宽/高均小于等于输入值'} ,\
}, \
b:Group{ orientation: 'row', \
c: Checkbox { text:' 不判断原图横竖',helpTip:'不根据原图的横竖自动对应尺寸,宽/高均以输入为准'} ,\
}, \
now:Group{ orientation: 'row', \
c: Checkbox { text:' 对文件夹进行操作(否则处理所有目前打开的文档)'} ,\
}, \
folderO:Group{ orientation: 'row', \
b: Button {text:'待处理文件夹', properties:{name:'open'} ,helpTip:'选择您需要处理的文件所在的文件夹'},\
s: EditText { text:'', preferredSize: [180, 20] },\
},\
other:Group{ orientation: 'row', \
c: Checkbox {text:' 启用另存'} ,\
g: Group {\
jpeg:RadioButton {text:'JPEG'},\
gif:RadioButton {text:'GIF'},\
psd:RadioButton {text:'PSD'},\
tiff:RadioButton {text:'TIFF'},\
}\
}, \
otherSet: Panel {orientation: 'column',alignChildren:'left',\
text: '另存设置', \
Quality: Group { orientation: 'row', \
c: Checkbox { text:'转换 ICC 配置',helpTip:'在储存前将 ICC 配置文件转换为 sRGB'} ,\
s: StaticText { text:'压缩质量:' }, \
d: DropDownList { alignment:'left', itemSize: [26, 14] },\
c2:Checkbox {text:'透明',helpTip:'包含基于颜色不透明度的透明性'},\
}, \
head: Group { orientation: 'row', \
s: StaticText { text:'在文件名前添加字符:' }, \
e: EditText { preferredSize: [50, 20] } ,\
s2: StaticText { text:'勿含非法字符' , enabled:flase }, \
}, \
foot: Group { orientation: 'row', \
s: StaticText { text:'在文件名后添加字符:' }, \
e: EditText { preferredSize: [50, 20] }, \
s2: StaticText { text:'勿含非法字符' , enabled:flase}, \
} ,\
otherF:Group{ orientation: 'row', \
c: Checkbox { text:' 另存至其他文件夹'} ,\
}, \
folderS:Group{ orientation: 'row', \
b: Button {text:'另存至', properties:{name:'save'} ,helpTip:'选择您处理好的文件要保存至的文件夹'},\
s: EditText { text:'', preferredSize: [180, 20] },\
},\
icc: Checkbox { text:' 储存时包含 ICC 配置文件',helpTip:'存为 GIF 格式时此选项无效'},\
},\
},\
buttons: Group { orientation: 'row', alignment: 'right',\
s:StaticText {text:'[ABOUT]'},\
Btnok: Button { text:'确定', properties:{name:'ok'} }, \
Btncancel: Button { text:'取消', properties:{name:'cancel'} } \
}, \
}";
win = new Window (res);
win.buttons.Btncancel.onClick = function () {
this.parent.parent.close();
}
win.buttons.s.onClick = function () {
alert(title+"\r\n首发:bbs.blueidea.com Photoshop专栏\r\n感谢:我爱蓝色、蛋蛋、clz8206、洛辰妃子");
}
function lock_b(){ //如果勾选了a,则b被锁定
if(win.group.a.c.value){
win.group.b.c.value=true;
}
}
win.group.a.c.onClick =function() { lock_b()};
win.group.b.c.onClick =function() { lock_b()};
// 打开文件夹的操作
var folderOpen=win.group.folderO
var folderSave=win.group.otherSet.folderS
folderOpen.b.onClick = function() {
var defaultFolder = folderOpen.s.text;
var testFolder = new Folder(defaultFolder);
if (!testFolder.exists) {
defaultFolder = "~";
}
var selFolder = Folder.selectDialog("选择待处理文件夹", defaultFolder);
if ( selFolder != null ) {
folderOpen.s.text = selFolder.fsName;
folderOpen.s.helpTip = selFolder.fsName.toString();
}
}
folderSave.b.onClick = function() {
var defaultFolder = folderSave.s.text;
var testFolder = new Folder(defaultFolder);
if (!testFolder.exists) {
defaultFolder = "~";
}
var selFolder = Folder.selectDialog("选择要储存至的文件夹", defaultFolder);
if ( selFolder != null ) {
folderSave.s.text = selFolder.fsName;
folderSave.s.helpTip = selFolder.fsName.toString();
}
}
// 初始化选项
if (app.documents.length == 0){
win.group.now.c.value = true;
win.group.folderO.enabled =true;
}else{
win.group.folderO.enabled =false;
}
win.group.other.g.enabled =false;
win.group.otherSet.enabled =false;
win.group.other.g.jpeg.value = true; //默认保存为jpg
win.group.otherSet.icc.value =true; //默认保存icc
var saveType = "jpeg";
win.group.otherSet.Quality.c2.hide(); //隐藏第二选框
for (i=0;i<13;i++){ //初始化jpeg质量下拉
win.group.otherSet.Quality.d.add("item", i );
}
win.group.otherSet.Quality.d.items[7].selected=true;
win.group.otherSet.Quality.d.helpTip ='JPEG 压缩质量 (值越大压缩后质量越高)';
//操作文件夹开关
win.group.now.c.onClick =function(){
if (win.group.folderO.enabled) {
win.group.folderO.enabled =false;
}else{
win.group.folderO.enabled =true;
}
}
//另存开关
win.group.other.c.onClick =function(){
if (win.group.otherSet.enabled) {
win.group.other.g.enabled =false;
win.group.otherSet.enabled =false;
win.text=title+'直接保存并关闭';
}else{
win.group.other.g.enabled = true;
win.group.otherSet.enabled =true;
win.text=title+'另存为并关闭';
if (!win.group.otherSet.otherF.c.value) {win.group.otherSet.folderS.enabled =false}
}
}
//另存至文件夹开关
win.group.otherSet.otherF.c.onClick =function(){
if (win.group.otherSet.folderS.enabled) {
win.group.otherSet.folderS.enabled =false;
}else{
win.group.otherSet.folderS.enabled =true;
}
}
//格式选项转换
win.group.other.g.jpeg.onClick =function() {
changeType("jpeg");}
win.group.other.g.gif.onClick =function() {
changeType("gif");}
win.group.other.g.psd.onClick =function() {
changeType("psd");}
win.group.other.g.tiff.onClick =function() {
changeType("tiff");}
//格式选项控制
function changeType(type){
saveType=type;
var don=win.group.otherSet.Quality;
switch (type) {
case "jpeg" :
don.c.text ='转换 ICC 配置' ;
don.c.helpTip ='在储存前将 ICC 配置文件转换为 sRGB'
don.c.value =false;
don.s.text ='压缩质量:';
don.d.helpTip ='JPEG 压缩质量 (值越大压缩后质量越高)';
don.d.removeAll();
for (i=0;i<13;i++){
don.d.add("item", i );
}
don.d.items[7].selected=true;
don.s.show();
don.d.show();
don.c2.hide();
win.text=title+'另存为 JPG 格式';
break;
case "gif" :
don.c.text ='启用扩散仿色' ;
don.c.helpTip ='储存为 GIF 格式时使用扩散防色算法'
don.c.value =true;
don.s.text ='颜色位数:';
don.d.helpTip ='GIF 颜色位数 (值越大压缩后质量越高)';
don.d.removeAll();
for (i=2;i<257;i=i*2){
don.d.add("item",i);
}
don.d.items[7].selected=true;
don.c2.value =true;
don.s.show();
don.d.show();
don.c2.show();
win.text=title+'另存为 GIF 格式';
break;
case "psd" :
don.c.text ='最大兼容' ;
don.c.helpTip ='储存为 PSD 格式是实现最大兼容'
don.c.value =true;
don.s.hide();
don.d.hide();
don.c2.hide();
win.text=title+'另存为 PSD 格式';
break;
case "tiff" :
don.c.text ='LZW压缩' ;
don.c.helpTip ='用 TIFF 格式储存时使用 LZW 压缩'
don.c.value =false;
don.s.hide();
don.d.hide();
don.c2.hide();
win.text=title+'另存为 TIFF 格式';
}
win.reload();
}
// 实际处理开始
function newsize(docRef,a,b,x,y){ //改变图象尺寸函数
var PW=x;
var PH=y;
if (x<1 || y<1) b=true; //有一个值空缺的时候,不判断横竖
if (!b && x<y){ //确保PW>=PH
PW=y;
PH=x;
}
var dw = docRef.width;
var dh = docRef.height;
var fw = PW;
var fh = PH;
if(!b && dh>dw){
fw = PH;
fh = PW;
}
if (x<1) fw=dw; //尺寸小于1则为 不做改变
if (y<1) fh=dh;
if(a){
w1 =dw/fw;
h1 =dh/fh;
if(w1>h1){
fh =dh/w1;
}else{
fw =dw/h1;
}
if (x<1 && y>=1) {fw=dw/h1;fh=y;} //有1个值不做限定的情况
if (y<1 && x>=1) {fh =dh/w1;fw=x;}
}
docRef.resizeImage(fw, fh, PRESOLUTION, ResampleMethod.BICUBIC);
}
function save(docRef) { //储存函数
if (win.group.other.c.value){ //判断是否另存
var don=win.group.otherSet.Quality;
var inEmbedICC=win.group.otherSet.icc.value;
var saveOptions;
switch (saveType) {
case "jpeg" :
docRef.flatten() ;//合并图层,以储存jpg
docRef.changeMode(ChangeMode.RGB); // 更改为rgb模式,避免其它模式无法储存
docRef.bitsPerChannel = BitsPerChannelType.EIGHT;
saveOptions = new JPEGSaveOptions();
saveOptions.quality = don.d.selection.index; //获取压缩质量
if (don.c.value) {
docRef.convertProfile("sRGB IEC61966-2.1", Intent.RELATIVECOLORIMETRIC, true, true);
}
saveOptions.embedColorProfile = inEmbedICC;
var typeName="jpg"; //定义后缀
break;
case "gif" :
docRef.changeMode(ChangeMode.RGB);
saveOptions = new GIFSaveOptions();
saveOptions.colors = don.d.selection.index;
if (don.c.value){
saveOptions.dither = Dither.DIFFUSION; //扩散仿色
}else{
saveOptions.dither = Dither.NONE;
} ;
if (don.c2.value) {
saveOptions.transparency=1;
}else{
saveOptions.transparency=0;
};
//saveOptions.matte = MatteType.NONE; //杂边无,否则为白色
saveOptions.interlaced = 0; //不交错
var typeName="gif";
break;
case "psd" :
saveOptions = new PhotoshopSaveOptions();
saveOptions.embedColorProfile = inEmbedICC;
var typeName="psd";
break;
case "tiff" :
docRef.flatten() ;
saveOptions = new TiffSaveOptions();
saveOptions.embedColorProfile = inEmbedICC;
if (don.c.value) {
saveOptions.imageCompression = TIFFEncoding.TIFFLZW;
} else {
saveOptions.imageCompression = TIFFEncoding.NONE;
}
var typeName="tif";
break;
default :
alert ("-_-!!! SaveType");
}
// 获取另存文件夹及前后追加字段
var headWord = win.group.otherSet.head.e.text;
var footWord = win.group.otherSet.foot.e.text;
if (win.group.otherSet.otherF.c.value){ //如果选中另存至文件夹
if (win.group.otherSet.folderS.s.text){
var saveFolder = win.group.otherSet.folderS.s.text+"/";
&