Highlighted

Combining files into one and saving - for multiple folders

New Here ,
Jul 10, 2020

Copy link to clipboard

Copied

I have around 200 folders, each of which contain no less than 2 and up to 10 images, all the same size. They are transparent png files which I want to combine and save as a jpeg in the same folder using the folder name. I believe that the change in file format will give me a white background rather than transparent so it will save me having to add a background layer to each. It also means that I don't need to load the files in any particular order. 

 

If it is only possible to run it for one folder, I can use Excel to generate a script for the other folders although I am not sure how large you can make a script. Something like

 

Script

---------Open Folder 1

---------Combine Files

---------Save Files

 

---------Open Folder 2

---------Combine Files

---------Save Files

 

and on and on although I am certain it isn't the best scripting practise and would offend any professional programmer. I naturally lean towards this method as I have written too many DOS batch files to be able to change my way of thinking.

 

From reading this forum I almost understand opening all the files in a folder (although not sure of the format if I am putting the folder name in the script rather than a pop up asking for it) and I can probably work out the combining and saving but changing folders has me confused.

 

Any suggestions will be greatly appreciated.

TOPICS
Actions and scripting

Views

90

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

Combining files into one and saving - for multiple folders

New Here ,
Jul 10, 2020

Copy link to clipboard

Copied

I have around 200 folders, each of which contain no less than 2 and up to 10 images, all the same size. They are transparent png files which I want to combine and save as a jpeg in the same folder using the folder name. I believe that the change in file format will give me a white background rather than transparent so it will save me having to add a background layer to each. It also means that I don't need to load the files in any particular order. 

 

If it is only possible to run it for one folder, I can use Excel to generate a script for the other folders although I am not sure how large you can make a script. Something like

 

Script

---------Open Folder 1

---------Combine Files

---------Save Files

 

---------Open Folder 2

---------Combine Files

---------Save Files

 

and on and on although I am certain it isn't the best scripting practise and would offend any professional programmer. I naturally lean towards this method as I have written too many DOS batch files to be able to change my way of thinking.

 

From reading this forum I almost understand opening all the files in a folder (although not sure of the format if I am putting the folder name in the script rather than a pop up asking for it) and I can probably work out the combining and saving but changing folders has me confused.

 

Any suggestions will be greatly appreciated.

TOPICS
Actions and scripting

Views

91

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
Jul 10, 2020 0
Adobe Community Professional ,
Jul 29, 2020

Copy link to clipboard

Copied

Hi,

Did you try something at your end with scripting? If yes, could you post your script version?

Best regards

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
Reply
Loading...
Jul 29, 2020 0
Adobe Community Professional ,
Jul 29, 2020

Copy link to clipboard

Copied

"I believe that the change in file format will give me a white background rather than transparent so it will save me having to add a background layer to each."

Yes, your belief is correct, JPG file format does not allow transparency and by default it will fill transparent area with white.

 

It also means that I don't need to load the files in any particular order.

It depends, I can not see your files nor I/we know your goal. If you do not have problem with order then Photoshop will not complain, it will merge files into single file in whatever order of layers. I am assuming that you are aware of layer order and how that thing work. What is on the top will cover everything below so only pixels which are on top of others will be visible in merged version or exported JPG file.

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
Reply
Loading...
Jul 29, 2020 0
Adobe Community Professional ,
Jul 29, 2020

Copy link to clipboard

Copied

Are the 200 folders all under a single common parent folder? If so, are there other folders under the top level folder that shouldn't be processed?

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
Reply
Loading...
Jul 29, 2020 0
Adobe Community Professional ,
Jul 29, 2020

Copy link to clipboard

Copied

Here is a start, I have adapted this from another script that I wrote... As I don't know the folder structure, it only works on a single top-level selected folder.

 

 

/* 
https://community.adobe.com/t5/photoshop/combining-files-into-one-and-saving-for-multiple-folders/td-p/11278199?page=1
Combining files into one and saving - for multiple folders

Script offering by Stephen Marsh
Use at your own risk, work on copies of the original files until you are happy that the script is working as you expect.
This script only works one folder at a time, the folder is manually selected each time the script is run.
*/

#target photoshop

// Capture original ruler units and set ruler units to pixels
var origUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;

/* Start Open Document Error Check - Part A: If */
if (app.documents.length == 0) {

    (function () {

        // Open the input folder
        var inFolder = Folder.selectDialog('Please select the folder containing the transparent PNG files:');
        // Test if Cancel button returns null, then do nothing
        if (inFolder == null) {
            return
        };

        // Only open PNG files
        var otherFiles = inFolder.getFiles(/\.(png)$/i);
        // Alpha numeric sort
        otherFiles.sort();

        // Set the input folder name for use as the final file name
        // Replace %20 with word spaces
        var inFolderName = inFolder.name.replace(/%20/g, ' ');

        // Open first file - dupe, rename & close
        var firstFile = app.open(File(otherFiles[0]));
        app.activeDocument.duplicate(inFolderName, false);
        firstFile.close(SaveOptions.DONOTSAVECHANGES);
        var combinedFile = app.activeDocument;

        // For all the other files in the inFolder...
        for (var i = 1; i < otherFiles.length; i++) {
            var openFiles = app.open(File(otherFiles[i]));

            // Dupe the other layers to the combined doc
            openFiles.layers[0].duplicate(combinedFile, ElementPlacement.PLACEATBEGINNING);
            openFiles.close(SaveOptions.DONOTSAVECHANGES);
        }

        // Return the original ruler units
        app.preferences.rulerUnits = origUnits;

        // Flatten
        app.activeDocument.flatten();

        // JPEG Options
        var jpegOptions = new JPEGSaveOptions();
        jpegOptions.quality = 12; // Quality Level
        jpegOptions.embedColorProfile = true; // or false
        jpegOptions.formatOptions = FormatOptions.STANDARDBASELINE;
        jpegOptions.matte = MatteType.NONE;

        // Save JPEG
        app.activeDocument.saveAs(new File(inFolder + '/' + inFolderName.split('.')[0] + '.jpg'), jpegOptions);
        app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

        alert('Finished!');

    })();
    /* Finish Open Document Error Check - Part A: If */

    /* Start Open Document Error Check - Part B: Else */
} else {
    alert('Please close all open files before running this script...');
}
/* Finish Open Document Error Check - Part B: Else */

 

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

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
Reply
Loading...
Jul 29, 2020 0
Adobe Community Professional ,
Aug 08, 2020

Copy link to clipboard

Copied

So, how did you go?

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
Reply
Loading...
Aug 08, 2020 0