Reputation: 145
I want to write a script that would substitute different text from a text file into my shalon and save the image in jpeg format.
An error occurs: "This function may not be available in this version of Photoshop" on this line:
activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE);
My code:
while(!myFile.eof)
{
line = myFile.readln();
createText(line);
var thistimestamp = Math.round(new Date().getTime() / 1000);
saveFile = new File( "/c/Users/marki/Desktop/Temp001/" +thistimestamp)
saveOptions = new JPEGSaveOptions();
saveOptions.embedColorProfile = true;
saveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
saveOptions.matte = MatteType.NONE;
saveOptions.quality = 9;
app.activeDocument.saveAs(saveFile, saveOptions, true,Extension.LOWERCASE);
}
I use Adobe Photoshop: 2017.0.0 20161012.r.53 2016/10/12:23:00:00 CL 1094006 ( x64)
Upvotes: 3
Views: 741
Reputation: 6949
You missed off the extension :D
saveFile = new File( "c:\\temp\\" + thistimestamp) + ".jpg");
Upvotes: 1
Reputation: 414
Taking that your script createFile()
is well defined and working, you are missing document creation command app.documents.add()
before you start issuing commands. You are also missing file open procedures. When added, the code works fine:
function createText(fface, size, colR, colG, colB, content, tX, tY) {
var artLayerRef = app.activeDocument.artLayers.add()
artLayerRef.kind = LayerKind.TEXT
textColor = new SolidColor();
textColor.rgb.red = colR;
textColor.rgb.green = colG;
textColor.rgb.blue = colB;
textItemRef = artLayerRef.textItem
textItemRef.font = fface;
textItemRef.contents = content;
textItemRef.color = textColor;
textItemRef.size = size
textItemRef.position = new Array(tX, tY)
}
var myFile = new File("/c/temp/myfile.txt");
myFile.open('r');
while(!myFile.eof) {
app.documents.add();
line = myFile.readln();
createText(line,10,2,2,2,line,10,10);
var thistimestamp = Math.round(new Date().getTime() / 1000);
saveFile = new File( "/c/temp/" +thistimestamp)
saveOptions = new JPEGSaveOptions();
saveOptions.embedColorProfile = true;
saveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
saveOptions.matte = MatteType.NONE;
saveOptions.quality = 9;
app.activeDocument.saveAs(saveFile, saveOptions, true, Extension.LOWERCASE);
}
This code is tested with version 20.0.2 20181219.r.30 2018/12/19: 1202136 x64
The text file content is:
And the result in Photoshop is:
Of course, all three documents are saved as jpegs in c:\temp.
In case you don't have a working createText
function, you can find an example in this article. The function in this example is taken from that article.
Upvotes: 0