我需要在 Photoshop 中创建 100 个单色 .png 文件,我可以在其中调用 CSV 文件中的十六进制值来更改图像的颜色并保存为 CSV 文件中的对应名称。
这样做的最佳方法是什么?
我需要在 Photoshop 中创建 100 个单色 .png 文件,我可以在其中调用 CSV 文件中的十六进制值来更改图像的颜色并保存为 CSV 文件中的对应名称。
这样做的最佳方法是什么?
下面是我读取 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;
}