【发布时间】:2016-09-16 09:33:59
【问题描述】:
大家好,我有这个脚本可以在 Photoshop 中将 EPS 文件转换为 Tiff。
目前它允许您选择要转换的文件文件夹并在其中为 Tiff 文件创建一个新文件夹。我曾尝试在同一个文件夹中创建 Tiff 而不创建额外的文件夹,但这似乎与原始 EPS 文件混淆。转换进行得很好,但它从 EPS 中取出数据并将其保存为空白文件。由于我将新转换的 Tiff 文件放在一个文件夹中,因此它也在其中创建了原始 EPS 的副本,我不需要。
基本上,我需要将文件夹中的所有 EPS 文件转换为 Tiffs,但不想弄乱原始 EPS,也不想要文件的其他副本。
我目前的脚本如下:
#include "~/AppData/Local/wbmUtils/lib/underscore.js";
//-------------- declare measurement in pixels and declare vars for HxW --------------\\
app.preferences.rulerUnits = Units.PIXELS;
var height =0;
var width = 0;
//-------------- select input and output folders --------------\\
alert("Choose a folder of EPS's");
var inPath = Folder.selectDialog();
var outPath = inPath+'/Tiffs';
$.writeln(inPath);
$.writeln(outPath);
//-------------- get full image list from input folder --------------\\
var inputs = getImageList (inPath);
function getImageList (dirPath)
{
var contents = dirPath.getFiles();
var imageList=[];
_.each(contents, function(item)
{
imageList.push(item.toString());
})
return imageList;
}
//-------------- create new folder for files --------------\\
$.writeln(inputs);
var imageFolderName = outPath;
var imageFolder = Folder(imageFolderName);
if(!imageFolder.exists) imageFolder.create();
_.each(inputs, function(input)
{
$.writeln("height: " + height + " width: " + width);
var imgWithExt = _.last(input.split('/'))
doPreviews(input, imageFolderName +'/' + imgWithExt);
var of = new File(input);
of.copy (imageFolderName +'/' + imgWithExt.split('.')[0] + '.eps');
})
//-------------- main conversion function --------------\\
function doPreviews(input, output)
{
var idOpn = charIDToTypeID("Opn ");
var desc4 = new ActionDescriptor();
var idnull = charIDToTypeID("null");
desc4.putPath(idnull, new File(input));
var idAs = charIDToTypeID("As ");
var desc5 = new ActionDescriptor();
var idRslt = charIDToTypeID("Rslt");
var idRsl = charIDToTypeID("#Rsl");
desc5.putUnitDouble(idRslt, idRsl, 300.000000);
var idAntA = charIDToTypeID("AntA");
desc5.putBoolean(idAntA, true);
var idEPSG = charIDToTypeID("EPSG");
desc4.putObject(idAs, idEPSG, desc5);
executeAction(idOpn, desc4, DialogModes.NO);
var idMk = charIDToTypeID("Mk ");
var desc7 = new ActionDescriptor();
var idnull = charIDToTypeID("null");
var ref1 = new ActionReference();
var idDcmn = charIDToTypeID("Dcmn");
ref1.putClass(idDcmn);
desc7.putReference(idnull, ref1);
var idUsng = charIDToTypeID("Usng");
var ref2 = new ActionReference();
var idHstS = charIDToTypeID("HstS");
var idCrnH = charIDToTypeID("CrnH");
ref2.putProperty(idHstS, idCrnH);
desc7.putReference(idUsng, ref2);
executeAction(idMk, desc7, DialogModes.NO);
height = app.activeDocument.height;
width = app.activeDocument.width;
if (height > width)
{
$.writeln("IS HIGHER THAN WIDE");
var idImgS = charIDToTypeID("ImgS");
var desc8 = new ActionDescriptor();
var idHght = charIDToTypeID("Hght");
var idPxl = charIDToTypeID("#Pxl");
desc8.putUnitDouble(idHght, idPxl, 6500.000000);
var idscaleStyles = stringIDToTypeID("scaleStyles");
desc8.putBoolean(idscaleStyles, true);
var idCnsP = charIDToTypeID("CnsP");
desc8.putBoolean(idCnsP, true);
var idIntr = charIDToTypeID("Intr");
var idIntp = charIDToTypeID("Intp");
var idautomaticInterpolation = stringIDToTypeID("automaticInterpolation");
desc8.putEnumerated(idIntr, idIntp, idautomaticInterpolation);
executeAction(idImgS, desc8, DialogModes.NO);
} else {
$.writeln("IS WIDER THAN HIGH");
var idImgS = charIDToTypeID("ImgS");
var desc32 = new ActionDescriptor();
var idWdth = charIDToTypeID("Wdth");
var idPxl = charIDToTypeID("#Pxl");
desc32.putUnitDouble(idWdth, idPxl, 6500.000000);
var idscaleStyles = stringIDToTypeID("scaleStyles");
desc32.putBoolean(idscaleStyles, true);
var idCnsP = charIDToTypeID("CnsP");
desc32.putBoolean(idCnsP, true);
var idIntr = charIDToTypeID("Intr");
var idIntp = charIDToTypeID("Intp");
var idautomaticInterpolation = stringIDToTypeID("automaticInterpolation");
desc32.putEnumerated(idIntr, idIntp, idautomaticInterpolation);
executeAction(idImgS, desc32, DialogModes.NO);
}
var idMk = charIDToTypeID("Mk ");
var desc20 = new ActionDescriptor();
var idnull = charIDToTypeID("null");
var ref4 = new ActionReference();
var idDcmn = charIDToTypeID("Dcmn");
ref4.putClass(idDcmn);
desc20.putReference(idnull, ref4);
var idUsng = charIDToTypeID("Usng");
var ref5 = new ActionReference();
var idHstS = charIDToTypeID("HstS");
var idCrnH = charIDToTypeID("CrnH");
ref5.putProperty(idHstS, idCrnH);
desc20.putReference(idUsng, ref5);
executeAction(idMk, desc20, DialogModes.NO);
var idCls = charIDToType("Cls ");
executeAction(idCls, desc20, DialogModes.NO);
//-------------- tiff options --------------\\
tiffSaveOptions = new TiffSaveOptions();
tiffSaveOptions.byteOrder = ByteOrder.MACOS;
tiffSaveOptions.layers = false;
tiffSaveOptions.transparency = true;
tiffSaveOptions.alphaChannels = true;
tiffSaveOptions.embedColorProfile = false;
tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;
tiffSaveOptions.saveImagePyramid = false;
app.activeDocument.saveAs(File(output.split('.')[0]+'.tiff'), tiffSaveOptions, true);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
//-------------- success message --------------\\
alert("ALL DONE!")
【问题讨论】:
-
要以从原始 eps 中删除数据的方式将文件放入原始文件夹,只需从第 11 行删除 +'/Tiffs' ,所以它只是说 var outPath = inPath;
标签: javascript photoshop tiff eps photoshop-script