From Photoshop actions to Photoshop scripting?

后端 未结 5 1301
伪装坚强ぢ
伪装坚强ぢ 2021-01-30 07:33

I would like Photoshop to automatically execute the following task for a given folder:

  1. Load all PNG files in a given folder.
  2. Convert each file\'s mode to
5条回答
  •  Happy的楠姐
    2021-01-30 08:17

    I made a script which does the required job:

    #target photoshop
    #strict on
    
    runthis();
    function runthis()
    {
        var path = "/d/PhotoshopScript/Images/";
    
         var inputFolder = new Folder(path );
        var inputFiles = inputFolder.getFiles("*.png");
    
        for(index in inputFiles)
        {
            // open the file
            var fileToOpen = new File(inputFiles[index]);
            open(fileToOpen);
    
            // Change mode to rgb
            activeDocument.changeMode(ChangeMode.RGB);
            // add a new layer
            activeDocument.artLayers.add();
    
            //save
            var psdOptions = new PhotoshopSaveOptions();
            psdOptions.alphaChannels = true;
            psdOptions.annotations = false;
            psdOptions.embedColorProfile = false;
            psdOptions.layers = true;
            psdOptions.spotColors = false;
    
            var file = new File(path + GetFileName(String(inputFiles[index])));
            activeDocument.saveAs(file, psdOptions);
    
            activeDocument.close();
    
            // dispose
            fileToOpen = null;
            psdOptions = null;
            file  = null;
        }
        // dispose
        inputFolder = null;
        inputFiles = null;
    
    }
    
    function GetFileName(fullPath)
    {
        var m = fullPath.match(/(.*)[\/\\]([^\/\\]+)\.\w+$/);
        return m[2];
    }
    

    It can be improved in many ways, but I hope it helps.

提交回复
热议问题