我需要在photoshop中创建100个单色.png文件,我可以从CSV文件中调用十六进制值来更改图像的颜色,并将其保存为CSV文件中的相应名称。
这样做的最佳方式是什么?
答案 0 :(得分:0)
以下是我读取csv文件的功能。获得颜色后,可以使用“app.documents.add()”创建具有初始填充颜色,保存等的新文档。有关详细信息,请在Photoshop安装目录中查看Photoshop JavaScript Reference pdf。
Misc.ReadCsvData = function (csvFile, bHeaderOnly) {
if (bHeaderOnly == undefined)
bHeaderOnly = false;
var line, temp, csvRecord, tempArr;
var csvData = new Array();
var tempArr2 = new Array();
csvFile.open("r");
var startsWithQuote = new RegExp('^\s*"');
var endsWithQuote = new RegExp('"\s*$');
var doubleQuotes = new RegExp('""', "g");
var hasData = new RegExp('[a-zA-Z0-9]');
var bInsideQuote = false;
var iFieldCount = -1;
var sTemp;
while (!csvFile.eof) {
line = csvFile.readln();
if (line.match(hasData)) {
tempArr = line.split(",");
tempArr2 = new Array();
for (var i = 0; i < tempArr.length; i++) {
if (!bInsideQuote && !tempArr[i].match(startsWithQuote)) {
tempArr2.push(tempArr[i].replace(doubleQuotes, '"'));
} else if (!bInsideQuote && tempArr[i].match(startsWithQuote) && tempArr[i].match(endsWithQuote)) {
tempArr2.push(tempArr[i].replace(startsWithQuote, "").replace(endsWithQuote, "").replace(doubleQuotes, '"'));
} else if (!bInsideQuote && tempArr[i].match(startsWithQuote)) {
bInsideQuote = true;
sTemp = tempArr[i];
} else if (bInsideQuote) {
sTemp = sTemp + ", " + tempArr[i];
if (tempArr[i].match(endsWithQuote)) {
tempArr2.push(sTemp.replace(startsWithQuote, "").replace(endsWithQuote, "").replace(doubleQuotes, '"'));
bInsideQuote = false;
}
}
}
if (iFieldCount < 0)
iFieldCount = tempArr2.length;
if (iFieldCount != tempArr2.length) {
throw "Cannot parse csv format.";
}
csvData.push(tempArr2);
if (bHeaderOnly)
break;
}
}
csvFile.close();
return csvData;
}