您的位置: 首页 > 技术文档 > 图形图像 > 批量更改图片尺寸的ps脚本
图层高级混合 【基础教程】 回到列表 超酷的金色组合
 批量更改图片尺寸的ps脚本

作者:xiexienile 时间: 2008-10-08 文档类型:原创 来自:蓝色理想

第 1 页 批量更改图片尺寸的ps脚本
第 2 页 批量更改图片尺寸的ps脚本—代码[1]
第 3 页 批量更改图片尺寸的ps脚本—代码[2]

#target photoshop
app.bringToFront();
// 带自动判断横竖的统一宽高操作。默认是直接保存关闭,原文件要注意备份! v2.0 - 2008.3.29
// 原发:bbs.blueidea.com  - Photoshop版
var nowTime=new Date();
var PRESOLUTION = 72;
var startRulerUnits = app.preferences.rulerUnits;
var startTypeUnits = app.preferences.typeUnits;
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;
var title="批量尺寸调整 v2.0 - "
        
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] },\
                                },\
                shui:Group{ orientation: 'row', \
                                c: Checkbox { text:' 为图片添加水印'} ,\
                                g: Group {\
                                        one:RadioButton {text:'单一' ,helpTip:'只添加一个水印图,可控制添加位置'},\
                                        fill:RadioButton {text:'平铺' ,helpTip:'多个水印图平铺布满画面,可控制间距'},\
                                    }\
                                }, \
                shuiSet: Panel {orientation: 'row', \
                        text: '水印设置', \
                                    position:Group{ orientation: 'column',alignChildren:'left',\
                                                po1:Group{ orientation: 'row',\
                                                    c1:Checkbox { helpTip:'以左上角为基准', preferredSize: [14, 14]} ,\
                                                    c2:Checkbox { helpTip:'以上中点为基准', preferredSize: [14, 14]} ,\
                                                    c3:Checkbox { helpTip:'以右上角为基准', preferredSize: [14, 14]} ,\
                                                    }, \
                                                po2:Group{ orientation: 'row', \
                                                    c4:Checkbox { helpTip:'以左中点为基准', preferredSize: [14, 14]} ,\
                                                    c5:Checkbox { helpTip:'以正中心为基准', preferredSize: [14, 14]} ,\
                                                    c6:Checkbox { helpTip:'以右中点为基准', preferredSize: [14, 14]} ,\
                                                    }, \
                                                po3:Group{ orientation: 'row', \
                                                    c7:Checkbox { helpTip:'以左下角为基准', preferredSize: [14, 14]} ,\
                                                    c8:Checkbox { helpTip:'以下中点为基准', preferredSize: [14, 14]} ,\
                                                    c9:Checkbox { helpTip:'以右下角为基准', preferredSize: [14, 14]} ,\
                                                    }, \
                                    },\
                                    other:Group{ orientation: 'column',alignChildren:'left',\
                                                dis:Group{ orientation: 'row',\
                                                    s1: StaticText { text:'平距:'}, \
                                                    e1: EditText { preferredSize: [55, 20], helpTip:'距离参照点的水平距离;平铺状态下为间距(单位:像素)' } ,\
                                                    s2: StaticText { text:'垂距:'}, \
                                                    e2: EditText { preferredSize: [55, 20], helpTip:'距离参照点的垂直距离;平铺状态下为间距(单位:像素)' } ,\
                                                },\
                                                hun:Group{ orientation: 'row',\
                                                    s: StaticText { text:'混合:'}, \
                                                    d:DropDownList { alignment:'left', itemSize: [50,16] },\
                                                    s2: StaticText { text:'缩放:'}, \
                                                    e:EditText{ preferredSize: [38, 20], text:'1',helpTip:'水印与原始水印文件的缩放比例'},\
                                                },\
                                                open:Group{ orientation: 'row', \
                                                    b: Button {text:'选择水印文件', properties:{name:'open'} ,helpTip:'请确保文件为常用图片格式,且非gif动画'},\
                                                    e: EditText  { text:'', preferredSize: [86, 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 () { //放弃
    app.preferences.rulerUnits = startRulerUnits;
    app.preferences.typeUnits = startTypeUnits;
    this.parent.parent.close();
}
win.buttons.s.onClick = function () {
alert("首发:bbs.blueidea.com  Photoshop专栏\r\n鸣谢:我爱蓝色、银子、蛋蛋、clz8206、洛辰妃子、Wonton",title+"关于");
}
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();
        }
}
win.group.shuiSet.other.open.b.onClick= function() //打开水印文件
{
    var selFile = File.saveDialog('选择水印文件');
    if ( selFile != null ) {
       win.group.shuiSet.other.open.e.text = selFile.fsName;
    }
}
// 初始化选项
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.shuiSet.enabled =false;
win.group.shui.g.enabled =false;
win.group.shui.g.one.value =true; //默认一个水印
win.group.shuiSet.position.po3.c9.value=true; //默认右下角
var jiaShui =false; //默认不添加水印
var sBlend=  new Array();
sBlend[0]= "正常,NORMAL";
sBlend[1]= "溶解,DISSOLVE";
sBlend[2]= "变暗,DARKEN";
sBlend[3]= "正片叠底,MULTIPLY";
sBlend[4]= "颜色加深,COLORBURN";
sBlend[5]= "线性加深,LINEARBURN";
sBlend[6]= "变亮,LIGHTEN";
sBlend[7]= "滤色,SCREEN";
sBlend[8]= "颜色减淡,COLORDODGE";
sBlend[9]= "线性减淡,LINEARDODGE";
sBlend[10]= "叠加,OVERLAY";
sBlend[11]= "柔光,SOFTLIGHT";
sBlend[12]= "强光,HARDLIGHT";
sBlend[13]= "亮光,VIVIDLIGHT";
sBlend[14]= "线性光,LINEARLIGHT";
sBlend[15]= "点光,PINLIGHT";
sBlend[16]= "实色混合,HARDMIX";
sBlend[17]= "差值,DIFFERENCE";
sBlend[18]= "排除,EXCLUSION";
sBlend[19]= "色相,HUE";
sBlend[20]= "饱和度,SATURATION";
sBlend[21]= "颜色,COLORBLEND";
sBlend[22]= "明度,LUMINOSITY";
//sBlend[23]= "深色,DARKERCOLOR";
//sBlend[24]= "浅色,LIGHTERCOLOR";
for (i=0;i<23;i++) {
    win.group.shuiSet.other.hun.d.add("item",sBlend[i].substring(0,sBlend[i].indexOf(",")));
}
win.group.shuiSet.other.hun.d.items[0].selected=true;
//操作文件夹开关
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.shui.c.onClick =function(){
    if (win.group.shui.g.enabled) {
        win.group.shui.g.enabled =false;
        win.group.shuiSet.enabled =false;
        }else{
        win.group.shui.g.enabled =true;
        win.group.shuiSet.enabled =true;
        }
}
//定位开关
var allp=win.group.shuiSet.position;
function pointClear(nowP) {            
            allp.po1.c1.value =false;
            allp.po1.c2.value =false;
            allp.po1.c3.value =false;
            allp.po2.c4.value =false;
            allp.po2.c5.value =false;
            allp.po2.c6.value =false;
            allp.po3.c7.value =false;
            allp.po3.c8.value =false;
            allp.po3.c9.value =false;
            nowP.value =true;
    }
allp.po1.c1.onClick =function() {pointClear(this)}
allp.po1.c2.onClick =function() {pointClear(this)}
allp.po1.c3.onClick =function() {pointClear(this)}
allp.po2.c4.onClick =function() {pointClear(this)}
allp.po2.c5.onClick =function() {pointClear(this)}
allp.po2.c6.onClick =function() {pointClear(this)}
allp.po3.c7.onClick =function() {pointClear(this)}
allp.po3.c8.onClick =function() {pointClear(this)}
allp.po3.c9.onClick =function() {pointClear(this)}
//格式选项转换
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 fillPattern(name,id,opacity) {  //填充图案
    var desc4 = new ActionDescriptor();
    desc4.putEnumerated( charIDToTypeID( "Usng" ), charIDToTypeID( "FlCn" ), charIDToTypeID( "Ptrn" ) );
        var desc5 = new ActionDescriptor();
        desc5.putString( charIDToTypeID( "Nm  " ), name );
        //desc5.putString(  charIDToTypeID( "Idnt" ), id );
    desc4.putObject( charIDToTypeID( "Ptrn" ), charIDToTypeID( "Ptrn" ), desc5 );
    desc4.putUnitDouble( charIDToTypeID( "Opct" ), charIDToTypeID( "#Prc" ), opacity );
    desc4.putEnumerated( charIDToTypeID( "Md  " ), charIDToTypeID( "BlnM" ), charIDToTypeID( "Nrml" ) );
    executeAction( charIDToTypeID( "Fl  " ), desc4, DialogModes.NO );
};
function setPattern(name) { //定义图案
    var desc13 = new ActionDescriptor();
        var ref7 = new ActionReference();
        ref7.putClass( charIDToTypeID("Ptrn") );
    desc13.putReference( charIDToTypeID("null"), ref7 );
        var ref8 = new ActionReference();
        ref8.putProperty( charIDToTypeID("Prpr"),charIDToTypeID("fsel") );
        ref8.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
    desc13.putReference( charIDToTypeID("Usng"), ref8 );
    desc13.putString( charIDToTypeID("Nm  "), name );
executeAction( charIDToTypeID("Mk  "), desc13, DialogModes.NO );    
}
function delPattern(){ //删除图案
    var desc92 = new ActionDescriptor();
        var ref53 = new ActionReference();
        ref53.putIndex( charIDToTypeID( "Ptrn" ), 178 );
    desc92.putReference( charIDToTypeID( "null" ), ref53 );
executeAction( charIDToTypeID( "Dlt " ), desc92, DialogModes.NO );
}
// 实际处理开始
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);
}

出处:蓝色理想
责任编辑:bluehearts

上一页 批量更改图片尺寸的ps脚本 下一页 批量更改图片尺寸的ps脚本—代码[2]

◎进入论坛PhotoshopFireworks版块参加讨论,我还想发表评论

相关文章
批量更改图片尺寸的ps脚本
关键字搜索 常规搜索 推荐文档
热门搜索:CSS Fireworks 设计比赛 网页制作 web标准 用户体验 UE photoshop Dreamweaver Studio8 Flash 手绘 CG
站点最新 站点最新列表
周大福“敬•自然”设计大赛开启
国际体验设计大会7月将在京举行
中国国防科技信息中心标志征集
云计算如何让安全问题可控
云计算是多数企业唯一拥抱互联网的机会
阿里行云
云手机年终巨献,送礼标配299起
阿里巴巴CTO王坚的"云和互联网观"
1499元买真八核 云OS双蛋大促
首届COCO桌面手机主题设计大赛
栏目最新 栏目最新列表
浅谈JavaScript编程语言的编码规范
如何在illustrator中绘制台历
Ps简单绘制一个可爱的铅笔图标
数据同步算法研究
用ps作简单的作品展示页面
CSS定位机制之一:普通流
25个最佳最闪亮的Eclipse开发项目
Illustrator中制作针线缝制文字效果
Photoshop制作印刷凹凸字体
VS2010中创建自定义SQL Rule
>> 分页 首页 前页 后页 尾页 页次:2/31个记录/页 转到 页 共3个记录

蓝色理想版权申明:除部分特别声明不要转载,或者授权我站独家播发的文章外,大家可以自由转载我站点的原创文章,但原作者和来自我站的链接必须保留(非我站原创的,按照原来自一节,自行链接)。文章版权归我站和作者共有。

转载要求:转载之图片、文件,链接请不要盗链到本站,且不准打上各自站点的水印,亦不能抹去我站点水印。

特别注意:本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有,文章若有侵犯作者版权,请与我们联系,我们将立即删除修改。

您的评论
用户名:  口令:
说明:输入正确的用户名和密码才能参与评论。如果您不是本站会员,你可以注册 为本站会员。
注意:文章中的链接、内容等需要修改的错误,请用报告错误,以利文档及时修改。
不评分 1 2 3 4 5
注意:请不要在评论中含与内容无关的广告链接,违者封ID
请您注意:
·不良评论请用报告管理员,以利管理员及时删除。
·尊重网上道德,遵守中华人民共和国的各项有关法律法规
·承担一切因您的行为而直接或间接导致的民事或刑事法律责任
·本站评论管理人员有权保留或删除其管辖评论中的任意内容
·您在本站发表的作品,本站有权在网站内转载或引用
·参与本评论即表明您已经阅读并接受上述条款
推荐文档 | 打印文档 | 评论文档 | 报告错误  
专业书推荐 更多内容
网站可用性测试及优化指南
《写给大家看的色彩书1》
《跟我去香港》
众妙之门—网站UI 设计之道
《Flex 4.0 RIA开发宝典》
《赢在设计》
犀利开发—jQuery内核详解与实践
作品集 更多内容

杂⑦杂⑧ Gold NORMANA V2