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

Combining files into one and saving - for multiple folders

New Here ,
Jul 10, 2020 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

285

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
Adobe
Community Expert ,
Jul 29, 2020 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

Votes

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 ,
Jul 29, 2020 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.

Votes

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 ,
Jul 29, 2020 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?

Votes

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 ,
Jul 29, 2020 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

Votes

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 ,
Aug 08, 2020 Aug 08, 2020

Copy link to clipboard

Copied

So, how did you go?

Votes

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 ,
Aug 08, 2020 Aug 08, 2020

Copy link to clipboard

Copied

LATEST

I believe it would be possible to script processing those PNG files.   The script would need a folders list.  Then would need to load the png files in each folder into a document.  The Canvas size would be  the width of the widest Png file and have the height of the tallest PNG file.  Now each layer can possibly  have a different layer's bounds for Photoshop trims a layers content to the layers object bounds. The script would know the number of layers in the document so it would be easy to save the width and height sizes  then  increase the document height to be (Number of Layers)*(original height)=New Canvas height. The Script would then set a selection Width by Original Height at the top of the canvas and  center the top layer into the selection center.  Then move the selection down by the original height and center the next layere down into the selected area repeat the process till all the layer have been positioned. Then save the Jpeg with the white background Close the document and then process the next folder the same way till all Jpegs have been saved. 

JJMack

Votes

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