复制代码代码如下:
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();
标签:
批量处理,图片大小
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
暂无“photoshop 批量处理图片大小的脚本代码”评论...
更新动态
2024年11月27日
2024年11月27日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]