Skip to main content
Participating Frequently
October 20, 2022
Question

Batch processing - Running myself ragged here about to give up

  • October 20, 2022
  • 6 replies
  • 488 views

PS2018

 

I've got hundreds of files I need to split into 6 equal sized quardrants from each part of the image and save each as different filenames. Sounds easy enough but seems not.

 

So far I've accomplished, with actions, copying each area into new file tabs, Then Save As, then Close All.

 

Run as Batch and Replace Save As saving sequentally, however each save overwrites the previous. So if I process 4 images I end up with 4 at the end instead of 24. 

 

I can't use the Image Processor for layers because it saves the entire layer, so will have a single quadrant in an image with the same LxW as the original large image.

 

Have also played with Export but no joy there either.

 

Any ideas? This is driving me crazy. 

 

Is there anyway to have the tabs load as the name of the original image with a 1, 2, 3 after it, instead of Untitled-1?

This topic has been closed for replies.

6 replies

Stephen Marsh
Community Expert
Community Expert
October 20, 2022
quote

Run as Batch and Replace Save As saving sequentally, however each save overwrites the previous. So if I process 4 images I end up with 4 at the end instead of 24.

 

Did you record the filename into the action? If so, you need to check the "override action save as command" checkbox in Batch.

 

https://helpx.adobe.com/photoshop/using/processing-batch-files.html#process_a_batch_of_files

 

I can't use the Image Processor for layers because it saves the entire layer, so will have a single quadrant in an image with the same LxW as the original large image.

 

You can use an action step that uses the "trim" command for transparent pixels.

 

Have also played with Export but no joy there either.

 

If you select all layers in the layers panel, then right-click and Export As...

 

Is there anyway to have the tabs load as the name of the original image with a 1, 2, 3 after it, instead of Untitled-1?

 

A script could do that.

 

Chuck Uebele
Community Expert
Community Expert
October 20, 2022

Try this script:

 

#target photoshop
var oldPref = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var doc0 = activeDocument;
var doc1, doc2, doc3, doc4, doc5, doc6;
var doc0W = doc0.width.value;
var doc0H = doc0.height.value;
var docName = doc0.name.split('.')[0];
var pngOptions = new PNGSaveOptions;
var dPath = doc0.path;
app.displayDialogs = DialogModes.NO; 


if(doc0W>doc0H){
    var split1 = Math.round(doc0W/3);
    var split2 = Math.round(doc0W/3) + split1;
    var split3 = Math.round(doc0H/2);
    dupFile (docName +'-1');
    doc1 = activeDocument
    cropImg (0, 0, split3, split1);
    activeDocument = doc0;
    dupFile (docName +'-2');
    doc2 = activeDocument    
    cropImg (0, split1, split3, split2)
    activeDocument = doc0;
    dupFile (docName +'-3');
    doc3 = activeDocument    ;
    cropImg (0, split2, split3, doc0W);  
    activeDocument = doc0;
    dupFile (docName +'-4');
    doc4 = activeDocument    ;
    cropImg (split3, 0, doc0H, split1);     
    activeDocument = doc0;
    dupFile (docName +'-5');
    doc5 = activeDocument    ;
    cropImg (split3, split1, doc0H, split2);       
    activeDocument = doc0;
    dupFile (docName +'-6');
    doc6 = activeDocument    ;
    cropImg (split3, split2, doc0H, doc0W);     
    }
else{
    var split1 = Math.round(doc0H/3);
    var split2 = Math.round(doc0H/3) + split1;
    var split3 = Math.round(doc0W/2);    
    dupFile (docName +'-1');
    doc1 = activeDocument
    cropImg (0, 0, split1, split3);   
    activeDocument = doc0;
    dupFile (docName +'-2');
    doc2 = activeDocument     
    cropImg (0, split3, split1, doc0W)
    activeDocument = doc0;
    dupFile (docName +'-3');
    doc3 = activeDocument;    
    cropImg (split1, 0, split2, split3);    
    activeDocument = doc0;
    dupFile (docName +'-4');
    doc4 = activeDocument    ;
    cropImg (split1, split3, split2, doc0W);     
    activeDocument = doc0;
    dupFile (docName +'-5');
    doc5 = activeDocument    ;
    cropImg (split2, 0, doc0H, split3);       
    activeDocument = doc0;
    dupFile (docName +'-6');
    doc6 = activeDocument    ;
    cropImg (split2, split3, doc0H, doc0W);     
    }

activeDocument = doc1;
doc1.saveAs (new File(dPath + '/' + docName + '-1.jpg'), pngOptions);
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
activeDocument = doc2;
doc2.saveAs (new File(dPath + '/' + docName + '-2.jpg'), pngOptions);
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
activeDocument = doc3;
doc3.saveAs (new File(dPath + '/' + docName + '-3.jpg'), pngOptions);
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
activeDocument = doc4;
doc4.saveAs (new File(dPath + '/' + docName + '-4.jpg'), pngOptions);
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
activeDocument = doc5;
doc5.saveAs (new File(dPath + '/' + docName + '-5.jpg'), pngOptions);
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
activeDocument = doc6;
doc6.saveAs (new File(dPath + '/' + docName + '-6.jpg'), pngOptions);
activeDocument.close(SaveOptions.DONOTSAVECHANGES);

app.preferences.rulerUnits = oldPref

function dupFile(fileName){
        var idDplc = charIDToTypeID( "Dplc" );
        var desc10 = new ActionDescriptor();
        var idnull = charIDToTypeID( "null" );
            var ref1 = new ActionReference();
            var idDcmn = charIDToTypeID( "Dcmn" );
            var idOrdn = charIDToTypeID( "Ordn" );
            var idFrst = charIDToTypeID( "Frst" );
            ref1.putEnumerated( idDcmn, idOrdn, idFrst );
        desc10.putReference( idnull, ref1 );
        var idNm = charIDToTypeID( "Nm  " );
        desc10.putString( idNm, fileName );
        var idMrgd = charIDToTypeID( "Mrgd" );
        desc10.putBoolean( idMrgd, true );
        var idDocI = charIDToTypeID( "DocI" );
        desc10.putInteger( idDocI, 65 );
    executeAction( idDplc, desc10, DialogModes.NO );
    }

function cropImg(topS,leftS,bottomS,rightS){
        var idCrop = charIDToTypeID( "Crop" );
        var desc367 = new ActionDescriptor();
        var idT = charIDToTypeID( "T   " );
            var desc368 = new ActionDescriptor();
            var idTop = charIDToTypeID( "Top " );
            var idRlt = charIDToTypeID( "#Rlt" );
            desc368.putUnitDouble( idTop, idRlt, topS );
            var idLeft = charIDToTypeID( "Left" );
            var idRlt = charIDToTypeID( "#Rlt" );
            desc368.putUnitDouble( idLeft, idRlt, leftS );
            var idBtom = charIDToTypeID( "Btom" );
            var idRlt = charIDToTypeID( "#Rlt" );
            desc368.putUnitDouble( idBtom, idRlt, bottomS );
            var idRght = charIDToTypeID( "Rght" );
            var idRlt = charIDToTypeID( "#Rlt" );
            desc368.putUnitDouble( idRght, idRlt, rightS );
        var idRctn = charIDToTypeID( "Rctn" );
        desc367.putObject( idT, idRctn, desc368 );
        var idAngl = charIDToTypeID( "Angl" );
        var idAng = charIDToTypeID( "#Ang" );
        desc367.putUnitDouble( idAngl, idAng, 0.000000 );
        var idDlt = charIDToTypeID( "Dlt " );
        desc367.putBoolean( idDlt, false );
        var idcropAspectRatioModeKey = stringIDToTypeID( "cropAspectRatioModeKey" );
        var idcropAspectRatioModeClass = stringIDToTypeID( "cropAspectRatioModeClass" );
        var idpureAspectRatio = stringIDToTypeID( "pureAspectRatio" );
        desc367.putEnumerated( idcropAspectRatioModeKey, idcropAspectRatioModeClass, idpureAspectRatio );
        var idCnsP = charIDToTypeID( "CnsP" );
        desc367.putBoolean( idCnsP, false );
    executeAction( idCrop, desc367, DialogModes.NO );
    }

 

Participating Frequently
October 20, 2022

thanks for this! the problem i ran into here was that it ignored the batch output destination setting because ignore save as not checked. checking it doesn't help because it also ignores the script saving nomenclature.

 

this results in the already cut and saved images being loaded and processed by the script.

Chuck Uebele
Community Expert
Community Expert
October 20, 2022

Another question: are the files both vertical and horizontal? Is the split with 3 parts along the longest side and the split with 2 along the short side? Can you post an example? 

Participating Frequently
October 20, 2022

  • Here's an example. So I just want to save each one of these as an individual png. I've got at least one method that works well for getting it split up, it's the saving with unique filenames... So I thought it had someway to have the newly created image area opened as a different name than untitled-#, then all would be gravy. Seems so strange there's no way to tick a box to auto save to a different filename (untitled-1 (1), untitled-1 (2) ) etc...). 

 

 

Chuck Uebele
Community Expert
Community Expert
October 20, 2022

So you want a compost of all the layers in each file split and saved? You don't have multiple layers in each file that you want split?

Chuck Uebele
Community Expert
Community Expert
October 20, 2022

You really need a script to do this, and it shouldn't be too difficult.

As far as the tabs loading with the name, again, you will need a script to that.