0

So the below script simply loops through a chosen folder, checks canvas size and dimensions and sets them if they're not in a 1:1 aspect ratio, and if they are, leaves them alone. The result is all images in the folder saved in 1:1 aspect ratio at dimension of 1000 x 1000 px.

The problem is they're all saved as .JPG whereas I would prefer to save them as transparent PNG-24.

I assume somewhere in the doc.save() method there is a parameter for different file types? I cannot find any documentation on this and was wondering if someone more knowledgeable knew? Thank you!

var inputFolder = Folder.selectDialog("Select a folder to process"),
      fileList = inputFolder.getFiles(/\.(jpg|tif|psd|crw|cr2|nef|dcr|dc2|raw)$/i);

for(var i=0; i < fileList.length; i++) {
    var doc = open(fileList[i]);
    if(doc.width !== doc.height) {
        if(doc.width > doc.height) {
            doc.resizeCanvas(doc.width, doc.width)
        } else {
            doc.resizeCanvas(doc.height, doc.height)
        }
    }
    if((doc.width && doc.height) > 1000) {
        doc.resizeImage(1000, 1000);
    } else {
        doc.resizeImage(doc.width, doc.height);
    }

    doc.save();
    doc.close();
}
5
  • 1
    I don't think this is the right stack for this question I'm afraid! You can see what kind of questions are accepted here: graphicdesign.stackexchange.com/help/on-topic I would possible try asking at webmasters.stackexchange.com Commented Sep 18, 2019 at 16:17
  • @JacksonHyde You’re right that it’s more about programming question rather than graphics but there are plenty of Adobe scripts questions floating around here. Commented Sep 18, 2019 at 18:34
  • 1
    @JacksonHyde Question is ok. Just slightly too much "do my work for me" like for my tastes.
    – joojaa
    Commented Sep 19, 2019 at 5:13
  • @exception-io Googling "photoshop script save png" gives hundreds and thousands correct answers, I wonder what exactly hindered you from finding an answer: what did you try, what didn't work? Commented Sep 19, 2019 at 12:32
  • I agree with @Sergey Kritskiy that it should've very easy to find answer and You said no documents available then look at this
    – Mr.Online
    Commented Sep 20, 2019 at 2:46

2 Answers 2

2

Here is the modified code

As per another answer, All you had to do was using "Save For Web" instead of save.

var inputFolder = Folder.selectDialog("Select a folder to process"),
      fileList = inputFolder.getFiles(/\.(jpg|tif|psd|crw|cr2|nef|dcr|dc2|raw)$/i);

for(var i=0; i < fileList.length; i++) {
    var doc = open(fileList[i]);
    if(doc.width !== doc.height) {
        if(doc.width > doc.height) {
            doc.resizeCanvas(doc.width, doc.width)
        } else {
            doc.resizeCanvas(doc.height, doc.height)
        }
    }
    if((doc.width && doc.height) > 1000) {
        doc.resizeImage(1000, 1000);
    } else {
        doc.resizeImage(doc.width, doc.height);
    }
    var fpath = fileList[i].path;
    var saveFile = new File (fpath);
    var pngSaveOptions = new ExportOptionsSaveForWeb();
    pngSaveOptions.format = SaveDocumentType.PNG;
    pngSaveOptions.PNG8 = false;
    pngSaveOptions.interlaced = false;
    app.activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, pngSaveOptions);
    doc.close(SaveOptions.DONOTSAVECHANGES);
}
0

You’d need either ‘Save As’ Or ‘Save for Web’ with options parameters in your script.

Here is a thread discussing same thing. I can only point you in right direction but can’t modify your code right now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.