Skip to main content
Participating Frequently
January 9, 2023
Question

Combining Tiffs

  • January 9, 2023
  • 4 replies
  • 2837 views

Hello,

 

Is it possible to combine few tiff's from a folder (mostly 8 but sometimes less) as a one new tiff containing all those tiff's from a folder as layers (names of the layers can be the names of the tiffs)?

 

Would be perfect is this could be done by a droplet (i put desired folder onto a droplet and as a result i get a signle tiff with multiple layers)

This topic has been closed for replies.

4 replies

Kevin Stohlmeyer
Community Expert
Community Expert
January 10, 2023

Hi @Michal278606593tfz are you on a Mac? If so, you could use Automator to run droplets on designated folders.

Participating Frequently
January 12, 2023

Hi, I'm on PC. I don't have access to Mac.

And I described wrong what I need.

 

I need one tiff with as many channels as there are 1-bit tiff files in the folder.

Converting those 1-bit tiff's into a channels takes so much time that it would help me so much if it could be automated.

c.pfaffenbichler
Community Expert
Community Expert
January 12, 2023

I took the liberty of adapting @Stephen Marsh ’s code, see if this helps. 

// 2023, use it at your own risk;
/*
adaption of 
Stacker - Dupe.jsx
Stephen Marsh, v1.2
*/

if (app.documents.length === 0) {
    (function () {
        var savedDisplayDialogs = app.displayDialogs;
        app.displayDialogs = DialogModes.NO;
        var origUnits = app.preferences.rulerUnits;
        app.preferences.rulerUnits = Units.PIXELS;

        var inputFolder = Folder.selectDialog('Please select the input folder:');
        if (inputFolder === null) {
            return;
        }

        var inputFiles = inputFolder.getFiles(/\.(jpg|jpeg|tif|tiff|png|psd|psb|gif)$/i);
        // inputFiles.sort().reverse;
        inputFiles.sort();

        var firstFile = app.open(File(inputFiles[0]));
        var firstFileName = app.activeDocument.name.replace(/\.[^\.]+$/, '');
        app.activeDocument.duplicate("Stacker", false);
        if (activeDocument.mode === DocumentMode.BITMAP) {
            activeDocument.changeMode(ChangeMode.GRAYSCALE);
        } else if (activeDocument.mode === DocumentMode.INDEXEDCOLOR) {
            activeDocument.changeMode(ChangeMode.RGB);
        }
        firstFile.close(SaveOptions.DONOTSAVECHANGES);
        var docStack = app.documents[0];
        app.activeDocument = docStack;
        docStack.activeLayer.name = firstFileName;

        for (var i = 0; i < inputFiles.length; i++) {
            var remainingFiles = app.open(File(inputFiles[i]));
            if (activeDocument.mode === DocumentMode.BITMAP) {
                activeDocument.changeMode(ChangeMode.GRAYSCALE);
            } else if (activeDocument.mode === DocumentMode.INDEXEDCOLOR) {
                activeDocument.changeMode(ChangeMode.RGB);
            }
            var fileName = remainingFiles.name.replace(/\.[^\.]+$/, '');
            remainingFiles.activeLayer.name = fileName;
            app.activeDocument = docStack;
            doCalculation (remainingFiles.name);
            activeDocument.channels[activeDocument.channels.length - 1].name = fileName;
            app.activeDocument = remainingFiles;
            remainingFiles.close(SaveOptions.DONOTSAVECHANGES);
        }

        app.beep();
        alert(inputFiles.length + ' files stacked!');
        app.displayDialogs = savedDisplayDialogs;
        app.preferences.rulerUnits = origUnits;


        // Functions
        function doCalculation (theFileName) {
            var idchannel = stringIDToTypeID( "channel" );
            var idordinal = stringIDToTypeID( "ordinal" );
            var idtargetEnum = stringIDToTypeID( "targetEnum" );
            var iddocument = stringIDToTypeID( "document" );
                var desc18 = new ActionDescriptor();
                desc18.putClass( stringIDToTypeID( "new" ), idchannel );
                    var desc19 = new ActionDescriptor();
                        var ref5 = new ActionReference();
                        ref5.putEnumerated( idchannel, idordinal, idtargetEnum );
                        ref5.putEnumerated( stringIDToTypeID( "layer" ), idordinal, stringIDToTypeID( "merged" ) );
                        ref5.putName( iddocument, theFileName );
                    desc19.putReference( stringIDToTypeID( "to" ), ref5 );
                        var ref6 = new ActionReference();
                        ref6.putEnumerated( idchannel, idordinal, idtargetEnum );
                        ref6.putEnumerated( stringIDToTypeID( "layer" ), idordinal, stringIDToTypeID( "merged" ) );
                        ref6.putName( iddocument, theFileName );
                    desc19.putReference( stringIDToTypeID( "source2" ), ref6 );
                desc18.putObject( stringIDToTypeID( "using" ), stringIDToTypeID( "calculation" ), desc19 );
            executeAction( stringIDToTypeID( "make" ), desc18, DialogModes.NO );
            };

        function align2SelectAll(method) {
            /*
            AdLf = Align Left
            AdRg = Align Right
            AdCH = Align Centre Horizontal
            AdTp = Align Top
            AdBt = Align Bottom
            AdCV = Align Centre Vertical
            */
            app.activeDocument.selection.selectAll();
            var desc = new ActionDescriptor();
            var ref = new ActionReference();
            ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
            desc.putReference(charIDToTypeID("null"), ref);
            desc.putEnumerated(charIDToTypeID("Usng"), charIDToTypeID("ADSt"), charIDToTypeID(method));
            try {
                executeAction(charIDToTypeID("Algn"), desc, DialogModes.NO);
            } catch (e) {}
            app.activeDocument.selection.deselect();
        }
    })();

} else {
    alert('Please close all open files before running this script...');
}

 

c.pfaffenbichler
Community Expert
Community Expert
January 9, 2023

I don’t think a droplet for Folders is plausible for Photoshop but other than that: How experienced are you with JavaScript and Photoshop’s DOM? 

Maybe JJMack’s PhotoCollageToolkit can prove useful to you: 

https://github.com/MarshySwamp/JJMack-Archive

Participating Frequently
January 9, 2023

Well I can't write a script but at least I know how to use them 😉

 

I asked about the droplet because the script won't speed up/automate too much, but of course it will be helpful.
I was hoping that what I need is not too complicated and I can automate it.

In a nutshell, the idea is to merge several tiff files (1-bit/bitmap) into one with layers (gray/cmyk whatever)

Stephen Marsh
Community Expert
Community Expert
January 9, 2023

Photoshop has a script – File > Scripts: "Load Files Into Stack"

 

This can also be scripted without the interface:

Participating Frequently
January 9, 2023

Many thanks for the answer.

I've checked that post above and I replied to You there.

That script is very promising but i can't get it work with 1-bit tiff.

c.pfaffenbichler
Community Expert
Community Expert
January 9, 2023

1bit images (in Photoshop aka »Bitmap images«) cannot have Layers. 

Chuck Uebele
Community Expert
Community Expert
January 9, 2023

With a script it can be done. There most likely are scripts that have been posted to the forum that can do something like this.