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

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

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

function shui(){ //水印处理函数
    if (!win.group.shuiSet.other.open.e.text) {
        alert("您没有选择水印文件");
    }else{
            var shuiFlie = File(win.group.shuiSet.other.open.e.text);
            docShui= open(shuiFlie);
            docShui.changeMode(ChangeMode.RGB);
            if (docShui.layers.length>1) docShui.mergeVisibleLayers(); //合并可见层
            var shuiLayer = docShui.activeLayer;
            
            if (parseInt(shuiLayer.bounds.toString().replace(/\D/g,"")) == 0) {
                docShui.close(SaveOptions.DONOTSAVECHANGES);
                if(confirm("水印文件内容为空,继续操作将不会添加任何水印")) go(false);//继续操作,只是不添加水印        
            }else{
                //拷贝水印
                var suo=Number(win.group.shuiSet.other.hun.e.text);
                if (!suo) suo=1; //容错
                if (suo<0) suo=1;
                docShui.resizeImage(docShui.width*suo,docShui.height*suo,PRESOLUTION, ResampleMethod.BICUBIC); //变换水印大小
                var sW=Number(shuiLayer.bounds[2]-shuiLayer.bounds[0]);
                var sH=Number(shuiLayer.bounds[3]-shuiLayer.bounds[1]);
                docShui.selection.selectAll();
                docShui.selection.copy();
                docShui.close(SaveOptions.DONOTSAVECHANGES);                
                //新建文档定义水印为图案
                if (win.group.shui.g.fill.value){
                    var newDR = app.documents.add(Number(win.group.shuiSet.other.dis.e1.text)+sW, Number(win.group.shuiSet.other.dis.e2.text)+sH, 72, "ShuiTu", NewDocumentMode.RGB, DocumentFill.TRANSPARENT);
                    newDR.paste();
                    newDR.selection.selectAll();
                    setPattern("BlueIdea-Script-Watermark-"+nowTime.toString());
                    newDR.close(SaveOptions.DONOTSAVECHANGES);                    
                    newDR= null;
                    }
                go(true,sW,sH);
            }
    }
}
function pasteShui(nWidth,nHeight,moveX,moveY,sW,sH,sHun){ //粘贴水印及偏移or 填充
    app.activeDocument.changeMode(ChangeMode.RGB);
    if(win.group.shui.g.one.value){
                switch (true) {
                    case (allp.po1.c1.value||allp.po2.c4.value||allp.po3.c7.value):
                        NowMX=moveX-nWidth/2+sW/2;
                        break;
                    case (allp.po1.c2.value||allp.po2.c5.value||allp.po3.c8.value):
                        NowMX=moveX;
                        break;
                    case (allp.po1.c3.value||allp.po2.c6.value||allp.po3.c9.value):
                        NowMX=nWidth/2-moveX-sW/2;
                        break;
                    default :
                        NowMX=0;
                }
                switch (true) {
                    case (allp.po1.c1.value||allp.po1.c2.value||allp.po1.c3.value):
                        NowMY=moveY-nHeight/2+sH/2;
                        break;
                    case (allp.po2.c4.value||allp.po2.c5.value||allp.po2.c6.value):
                        NowMY=moveY;
                        break;
                    case (allp.po3.c7.value||allp.po3.c8.value||allp.po3.c9.value):
                        NowMY=nHeight/2-moveY-sH/2;
                        break;
                    default :
                        NowMY=0;
                }                 
                app.activeDocument.paste();
                app.activeDocument.activeLayer.translate (NowMX,NowMY);
    }else{
            app.activeDocument.artLayers.add();
            app.activeDocument.selection.selectAll();
            fillPattern("BlueIdea-Script-Watermark-"+nowTime.toString(),"id",100);
    }
    app.activeDocument.activeLayer.blendMode =eval("BlendMode."+sHun);
}
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" :
                            if (docRef.artLayers.length>1)docRef.mergeVisibleLayers(); //合并可见层
                            docRef.changeMode(ChangeMode.RGB);
                            saveOptions = new GIFSaveOptions();
                            saveOptions.colors = Math.pow(2,don.d.selection.index+1);
                            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+"/";    
                            }else{    
                                var saveFolder = docRef.path+"/newsize_";  //容错,避免没有具体选择另存到那个文件夹
                            }
                }else{
                            if (headWord || footWord){
                                var saveFolder = docRef.path+"/";
                            }else{
                                var saveFolder = docRef.path+"/newsize_"; //容错,避免没有添加前后缀而保存在本文件夹
                            }
                }
                if (docRef.name.lastIndexOf('.')==-1){  //根据原文件名有否后缀,判断是否去掉后缀
                        var oldname=docRef.name;
                    }else{
                        var oldname=docRef.name.substring(0,docRef.name.lastIndexOf('.'));
                    }
                
            docRef.saveAs(new File(saveFolder + headWord + oldname + footWord + "."+ typeName),saveOptions, true,Extension.LOWERCASE);    //设定输出文件名称            
        }else{
            docRef.save();
        }
        docRef.close(SaveOptions.DONOTSAVECHANGES); //关闭当前文档    
}
function go(shuiOK,sW,sH) { //最后循环处理及关闭
        var x=Number(win.group.corrdination.x.e.text);
        var y=Number(win.group.corrdination.y.e.text);
        var a=win.group.a.c.value;
        var b=win.group.b.c.value; //选中则不颠倒横竖,以输入值为准    
    
        if (saveType=="psd"){ //变更首选项
        var rememberMaximize = app.preferences.maximizeCompatibility; //psd格式最大兼容 原始选项 --记录
        var needMaximize = win.group.otherSet.Quality.c.value? QueryStateType.ALWAYS : QueryStateType.NEVER;
            if ( app.preferences.maximizeCompatibility != needMaximize ) {
                        app.preferences.maximizeCompatibility = needMaximize;
                }
        }        
        
        if (shuiOK){ //获取水印偏移量及混合模式
        var mdis =win.group.shuiSet.other.dis;
        var moveX=Number(mdis.e1.text),moveY=Number(mdis.e2.text);
            for (i=0;i<23;i++) {
                if (win.group.shuiSet.other.hun.d.items[i].selected==true){
                    var sHun=sBlend[i].substring(sBlend[i].indexOf(",")+1);
                    break;
                    }
            }
        }
        
        if (!win.group.now.c.value) {  // 当前活动文档为操作对象    
                var k=100/app.documents.length; //定义每个文件所占进度比例
                while (app.documents.length){
                        var docRef = app.activeDocument;
                        newsize(docRef,a,b,x,y);
                        if(shuiOK) pasteShui(Number(docRef.width),Number(docRef.height),moveX,moveY,sW,sH,sHun);
                        save(docRef);
                        win.group.timeline.value =win.group.timeline.value+k;
                }
        }else{ // 文件夹为操作对象            
                var openFolder = Folder(win.group.folderO.s.text);                
                var fileList = openFolder.getFiles() //获取open文件夹下所有文件
                var k=100/fileList.length;
                for (i=0;i<fileList.length;i++){
                    if (fileList[i] instanceof File && fileList[i].hidden == false){ //不处理隐藏文件
                        open(fileList[i]);
                        var docRef = app.activeDocument;
                        newsize(docRef,a,b,x,y);
                        if(shuiOK) pasteShui(Number(docRef.width),Number(docRef.height),moveX,moveY,sW,sH,sHun);
                        save(docRef);
                    }
                    win.group.timeline.value =win.group.timeline.value+k;
                }
        }
    
    if ( rememberMaximize != undefined )  app.preferences.maximizeCompatibility = rememberMaximize;  //psd格式最大兼容选项还原
    app.preferences.rulerUnits = startRulerUnits;
    app.preferences.typeUnits = startTypeUnits;
    if (shuiOK && win.group.shui.g.fill.value) delPattern(); //清除图案定义
    this.parent.parent.close();
}
win.buttons.Btnok.onClick = function () {    
        if (win.group.shui.c.value) {
            shui(); //处理水印及最后完成
        }else{
            go(false);
        }
}
win.center();
win.show();

 

本文链接:http://www.blueidea.com/tech/graph/2008/6216.asp 

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

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

◎进入论坛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
>> 分页 首页 前页 后页 尾页 页次:3/31个记录/页 转到 页 共3个记录

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

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

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

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

杂⑦杂⑧ Gold NORMANA V2