Javascript 如何从文件中加载数据
我在Photoshop中有一个脚本,但我需要一件事。我想从文件中获取(解析)宽度和高度数据。我该怎么做?文件可以是txt或xml。我使用Photoshop中的ExtendScript工具包Javascript 如何从文件中加载数据,javascript,photoshop-script,Javascript,Photoshop Script,我在Photoshop中有一个脚本,但我需要一件事。我想从文件中获取(解析)宽度和高度数据。我该怎么做?文件可以是txt或xml。我使用Photoshop中的ExtendScript工具包 谢谢你的帮助我还是有点不明白你想要什么。 但是,您可以使用以下方法将文本文件作为数据加载到Photoshop中: function readIt(fName) { var theFile = new File(fName); //read in file var words = [
谢谢你的帮助我还是有点不明白你想要什么。 但是,您可以使用以下方法将文本文件作为数据加载到Photoshop中:
function readIt(fName)
{
var theFile = new File(fName);
//read in file
var words = [];
var textFile = new File(theFile);
textFile.open('r');
while(!textFile.eof)
{
var line = textFile.readln();
if (line != null && line.length >0)
{
words.append(line);
}
}
textFile.close();
// return array
return words;
}
我只想从一个文件中获取2个变量,在编写代码之前,我需要var width=(文件中的第一个数据)和var height=(第二个数据)。当我得到这个时,我可以修改脚本,使其看起来像:
if ( activeDocument.width != width || activeDocument.height != height ) {
displayDialogs = DialogModes.ALL;
activeDocument.resizeImage( width, height, 72, ResampleMethod.BICUBIC );
displayDialogs = DialogModes.NO;
}
在您的代码中,我将该文件中的所有内容都放在一个变量“words”中,您能更好地解释一下您想做什么吗?使用var imgW=app.activeDocument.width,可以找到图像的宽度(在Photoshop中打开后);我有f.ex150150的文件,我想把这些数据放到这个脚本中。目前,脚本使图片100x100和72dpi。我不知道如何从文件中获取数据
if ( activeDocument.width != width || activeDocument.height != height ) {
displayDialogs = DialogModes.ALL;
activeDocument.resizeImage( width, height, 72, ResampleMethod.BICUBIC );
displayDialogs = DialogModes.NO;
}