• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

SaveAs JPEG not working in script - HELP!

New Here ,
Jan 22, 2023 Jan 22, 2023

Copy link to clipboard

Copied

Hi, I am working on a script to add text to a series of JPG files in a folder and overwrite those jpg files with a jpeg quality of 10. I am SOOOOO close to getting it to work but for some reason, the file won't save as JPEG it continues to save as PSD. I am new and trying t use ChatGPT but this is as far as I've gotten, any help is appreciated, thanks.

 

// Declare variables for the text and the text layer
var text, textLayer;

// Open a window for the user to enter text
text = prompt("Enter some text:", "Type your text here");

// Define the folder where the files are located
var sourceFolder = Folder.selectDialog("Select the source folder:");

// Get a list of the files in the folder
var fileList = sourceFolder.getFiles();

// Save folder
var saveFolder = sourceFolder.parent;

// Loop through the list of files
for (var i = 0; i < fileList.length; i++) {
  // Open the file
  var file = open(fileList[i]);

  // Create a new text layer
  var textLayer = file.artLayers.add();
  textLayer.kind = LayerKind.TEXT;
  textLayer.textItem.contents = text;
  textLayer.textItem.position = Array(10, 1064);
  textLayer.textItem.size = 11;
  textLayer.textItem.font = "Californian FB Bold";
  textLayer.textItem.textcolor =  new SolidColor();
  textLayer.textItem.color.rgb.red = 230;
  textLayer.textItem.color.rgb.green = 10;
  textLayer.textItem.color.rgb.blue = 10;

// Set the name of the text layer to "ID"
textLayer.name = "ID";


// Find the layer named "ID"
var idLayer = activeDocument.layers.getByName("ID");

// Set the text of the "ID" layer to the user's text
idLayer.textItem.contents = text;

// Save the file
var jpegOptions = new JPEGSaveOptions();
jpegOptions.quality = 10; // really high
file.saveAs(new File(saveFolder + "/modified_file" + i +".jpg"), jpegOptions, true);

file.close();
}

 

TOPICS
Windows

Views

177

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 22, 2023 Jan 22, 2023

Copy link to clipboard

Copied

You need to flatten it, or change your preferences so that it will save the old way and not save as copy. You could also script it to save as a copy, if you don't want to or can't change the preferences. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 23, 2023 Jan 23, 2023

Copy link to clipboard

Copied

LATEST

Can you use this as part of an action? Run the script and have the action flatten and save.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines