在Photoshop中用javascript复制图像并添加编号

来源:互联网 发布:linux渗透测试工具 编辑:程序博客网 时间:2024/06/05 02:17

所里办毕业晚会,需要制作抽奖卡片,但为卡片自动编号是一个很棘手的问题,因为需要在卡片特定的位置加编号,且每一页A4纸可以做成多张卡片。下面以每页3张卡片,每张卡片添加两个编号为例,在Photoshop中用javascript编写脚本实现该功能。

/*******************************************************************************************************This script is to add incremental numbers to the fixed positions in multiple copies of a picture.********************************************************************************************************/docRef = app.activeDocument;jpegSaveOpt  = new JPEGSaveOptions();jpegSaveOpt.quality = 10;MAX_PAGE_NUM = 100;MAX_POS_NUM = 3;xLeft= 1.3;yArrLeft= [2.5, 12.5, 22.5];xRight = 18.5;yArrRight = [1.5, 11.5, 21.5];for(cnt=1; cnt<=MAX_PAGE_NUM; cnt++){layers = Array(MAX_POS_NUM*2,docRef.artLayer);i=0;for(pos=0; pos<MAX_POS_NUM; pos++){layers[i++] = drawNum(xLeft, yArrLeft[pos], cnt, pos);layers[i++] = drawNum(xRight, yArrRight[pos], cnt, pos);}saveFolder = "dst/";mFile = new File(saveFolder + cnt + ".jpg");expOptForWeb = new ExportOptionsSaveForWeb();expOptForWeb.format = SaveDocumentType.JPEG;expOptForWeb.quality = 80;docRef.exportDocument(mFile, ExportType.SAVEFORWEB, expOptForWeb);for(i=0;i<layers.length;i++){layers[i].remove();}}/************************************************Function: to add number at (x,y).Input:x: x-coordinatey: y-coordinatecnt: page numberpos: position number on a page************************************************/function drawNum(x,y,cnt,pos){docRef = app.activeDocument;layerRef = docRef.artLayers.add();layerRef.name = "num"+pos;layerRef.kind = LayerKind.TEXT;textItemRef= layerRef.textItem;textItemRef.position=Array(x,y);size = 30;textItemRef.size = size;mCnt= 3*cnt-2+pos;textItemRef.contents = addZeros(mCnt);return layerRef;}/************************************************Function: to add zeros in front of number.Input:cnt: page number************************************************/function addZeros(cnt){if(cnt<10){cntStr = "00" + cnt.toString();}else if(cnt<100){cntStr = "0" + cnt.toString();}else{cntStr = cnt.toString();}return cntStr;}
当然也可以每页只制作一张卡片,为其添加编号,然后在打印的时候每页纸打印多张卡片。

0 0
原创粉丝点击