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

Cut the same image multiple times with batch

Explorer ,
Aug 02, 2021 Aug 02, 2021

Copy link to clipboard

Copied

Hi, I have a problem with a batch in Photoshop, I have been looking around for a while, but I have not found a real solution.

 

I have to cut images into several parts. From a single image I have to get two or four by cutting them in half or cross.

I made an action and if I manually activate it, it works fine (I set a stop at each save and manually put a different name each time to the file I save, 01, 02 etc ..).

However, if I automate the action with the batch by giving a source folder, a destination folder and activating "Ignore Save As commands", setting the saving with only two-digit serial number and extension, in the end I only get 4 files instead of 8 (choosing the action that cuts the image in half).

 

Batch.png

Single Action.png

  

I also tried to create two distinct actions (one for the upper half and one for the lower half) and to use Image Processo Pro, but also in this case I get 4 files instead of 8.

Processor Pro 01.png

Processor Pro 02.png

Two actions.png

   

What I would like to obtain is an automated action / batch that in one shot (possibly without closing and reopening the original image, because each file I have to cut is about 1GB) creates and saves two or four portions from a single image.

 

At the following link a zip with the actions and 4 small images to be cut in half (as an example)

Archivio-test.zip

TOPICS
Actions and scripting

Views

1.6K

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
Explorer ,
Aug 02, 2021 Aug 02, 2021

Copy link to clipboard

Copied

Maybe I understand where I'm wrong.
In the action I have to put only the cutting of the image, without the action of saving and closing it, then Image processor Pro will take care of saving inside the various sets folder and closing the image.
Right?

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 02, 2021 Aug 02, 2021

Copy link to clipboard

Copied

First of all if you want to batch an action the action  should not have any interactive steps. Batch should be a fully automated process.

 

Second if you want to have multiple image files saved out. You need to realize that Actions have limited saving capabilities. They can only save the current document. If the want to batch the action no file name should be recorded in the Save As step. So Photoshop will use the current document File Name its default operation.  Therefor you need to save each output image file into a different folder for they will have the same file names.

 

Third in you action set I saw no actions that cut images into parts and save each part as an image file.

 

 

So I create a CutUpImage action set and recorded a batch action the  doe the Top Button cutup. Output image file will be save o sub folders "Top" and "Bottom" in a folder name "ImageSave" which is on your desktop.  You need to create thees folders before you use the action.

 

CutUpImage.atn  I use Photoshop's 22.4.3 "Enable legacy "Save As"" preference for Photoshop 22.4.2  "Save As" brakes too many actions.

 

image.png

image.png

 

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
LEGEND ,
Aug 02, 2021 Aug 02, 2021

Copy link to clipboard

Copied

Off-topic: I noticed you don't have enabled Private Messages. Is that intentional?

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 02, 2021 Aug 02, 2021

Copy link to clipboard

Copied

I turned off all Email notifications and never turned on provate messages. I just truned on private messages. If I do not get many I'll leave it on.

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
LEGEND ,
Aug 02, 2021 Aug 02, 2021

Copy link to clipboard

Copied

Thank You. I was able to sent you a message 😉

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 02, 2021 Aug 02, 2021

Copy link to clipboard

Copied

You can use the free Download "Image  Processor Pro" Photoshop Plug-in Script. The script can run up to 10 actions on your mages to crop and output images and save into the same output folder with Image name to note the crop part they are like "Document Name Top", "Document Name Bottom", Document Name Top Left", Document Name Top Right",  "Document Name Bottom Left", "Document Name Bottom Right".  Image Processor Pro when installed is  menu File>Automate>Image Processor Pro...

Scripts can name file well. The action select the crop area via select fixed sized percentage area where you click outside the four corner to select the correct location. That followed by menu Image>Crop.

 

The  Crop Sizes are (Be sure to set Preferences ruler units to percentage first

Width 100%, Height 50%

and

Width 50% and Height 50%.

 

image.png

image.png

 

image.png

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
Explorer ,
Aug 03, 2021 Aug 03, 2021

Copy link to clipboard

Copied

Hi JJMack, thank you very much for your reply.
I can't download your "CutUpImage.atn" action, it always gives me error.

I looked at the image of your action but it seems a little too complex (there are some steps that I don't understand why there are such as "make layer", "flatten", "paste", "Align", etc).

 

In any case I created 4 very simple actions that only cut the image in half (Top left, Top Right, Bottom Left, Bottom Right), then I performed them with Image Processor Pro and I get the 4 desired files in 4 different sets.

01.png

02.png

03.png

04.png

 

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 03, 2021 Aug 03, 2021

Copy link to clipboard

Copied

The best was to deals with various image sizes in actions is to work with relative size. Using ruler units percentage.

 

The code you did not understand in the batch action was there so the action could work on source images in any file format. The action added an empty layer to insure the current document was layered if the source image was flat. The action then flatten so any source image would be flattened, once  flattened the background was converted to a normal layer. Then relative size sections were cute from the bottom layer and stacked with paste.  Once the  Image was all diced up into same size pieces the layer were aligned to the top left so all the pieces were on top of each other. The canvas was then trimmed so the document canvas size became the diced up size then  action saved the top layer the a folder delete the top layer save the new top later to a different folder  etc. then closed the document no save. The single action dices and saved.  But needed to use  prepared output folder  for actions can not set output file names and needs Photoshop to use the current documents name for each save so all diced up images for an image will have the same name they need to be us a different output folders. Save As can set known folders for outputting files and have photoshop set the current file name.  Image Processor is a script. Scripts can generated and set output file manes.

 

Output file will be jpeg however input image files can be any image file formats.

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
Explorer ,
Aug 03, 2021 Aug 03, 2021

Copy link to clipboard

Copied

For now I will use the method I found with "Actions + Image Processor Pro" because it easily achieves the goal.
Yours is a great method in case I need something different.

Thanks again for the answers.

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 04, 2021 Aug 04, 2021

Copy link to clipboard

Copied

LATEST

The image processor pro is the way to do it with simple crop actions.  The Image Processor  Pro Script did not always exists. Adobe Image Processor script can only save three different image for each image file processed  So we needed to record complex batachable actions to cut up Images. 

 

In 2015 c.pfaffenbichler posted a script the can cut up an image using guidelines  you set. So it is easy record an interactive action to use menu view new guideline layouts. Dice up and image for the layout with a script step then delete the the backgrounds layer align all layer to the top left trim the user export layers to files.  Image Processor pro is limited to 10 output file. What it  you want 16 a 4x4 cutout...

Capture.jpg

 

// Dice layer with according to guides;
// 2015, use it at your own risk;
#target photoshop

if (app.documents.length > 0) {
	var myDocument = app.activeDocument;
	var myResolution = myDocument.resolution;
	var theLayer = myDocument.activeLayer;
	var layerID = getLayerId(theLayer);
	var originalRulerUnits = app.preferences.rulerUnits;
	app.preferences.rulerUnits = Units.POINTS;
	// check guides;
	var theVer = new Array;
	var theHor = new Array;
	var theNumber = myDocument.guides.length;
	for (var m = 0; m < theNumber; m++) {
		if (myDocument.guides[m].direction == Direction.HORIZONTAL) {theHor.push(myDocument.guides[m].coordinate)};
		if (myDocument.guides[m].direction == Direction.VERTICAL) {theVer.push(myDocument.guides[m].coordinate)};
	};
	// sort and add beginning and end;
	theHor = treatGuideArray (theHor, app.activeDocument.height);
	theVer = treatGuideArray (theVer, app.activeDocument.width);
	$.writeln(theHor.join("\n")+"\n\n\n"+theVer.join("\n"));
	// create selections;
	for (var y = 0; y < theHor.length - 1; y++) {
		var Y1 = theHor[y];
		var Y2 = theHor[y+1];
		for (var x = 0; x < theVer.length - 1; x++) {
			try {
				var X1 = theVer[x];
				var X2 = theVer[x+1];
				rectangularSelection([Y1, X1, Y2, X2], false);
				// layer via copy;
				var id14 = charIDToTypeID( "CpTL" );
				executeAction( id14, undefined, DialogModes.NO );
				// add mask;
				intersectedLayerMask (layerID)
			} catch (e) {};
		// reselct layer;
		myDocument.activeLayer = theLayer;
		};
	};
	activeDocument.selection.deselect();
	// reset the ruler units;
	app.preferences.rulerUnits = originalRulerUnits
};
////////////////// the functions //////////////////
////// treat array //////
function treatGuideArray (theArray, theExtreme) {
	theArray.sort(function(a,b){return a - b});
	if (Number (theArray[theArray.length - 1]) != theExtreme) {theArray.push(theExtreme)};
	if (Number (theArray[0]) != 0) {theArray.unshift(new UnitValue(0, "pt"))};
	theArray.sort(function(a,b){return a - b});
	return theArray;
};
////// rectangular selection //////
function rectangularSelection (theBounds, add) {
	// =======================================================
	if (add == false ||  add == undefined) {var idsetd = charIDToTypeID( "setd" )}
	else {var idsetd = charIDToTypeID( "AddT" )};
		var desc55 = new ActionDescriptor();
		var idnull = charIDToTypeID( "null" );
			var ref11 = new ActionReference();
			var idChnl = charIDToTypeID( "Chnl" );
			var idfsel = charIDToTypeID( "fsel" );
			ref11.putProperty( idChnl, idfsel );
		desc55.putReference( idnull, ref11 );
		var idT = charIDToTypeID( "T   " );
			var desc56 = new ActionDescriptor();
			var idTop = charIDToTypeID( "Top " );
			var idRlt = charIDToTypeID( "#Rlt" );
			desc56.putUnitDouble( idTop, idRlt, theBounds[0] );
			var idLeft = charIDToTypeID( "Left" );
			var idRlt = charIDToTypeID( "#Rlt" );
			desc56.putUnitDouble( idLeft, idRlt, theBounds[1] );
			var idBtom = charIDToTypeID( "Btom" );
			var idRlt = charIDToTypeID( "#Rlt" );
			desc56.putUnitDouble( idBtom, idRlt, theBounds[2] );
			var idRght = charIDToTypeID( "Rght" );
			var idRlt = charIDToTypeID( "#Rlt" );
			desc56.putUnitDouble( idRght, idRlt, theBounds[3] );
		var idRctn = charIDToTypeID( "Rctn" );
		desc55.putObject( idT, idRctn, desc56 );
	executeAction( idsetd, desc55, DialogModes.NO );
};
// by mike hale, via paul riggott;
function getLayerId(theLayer){
	// http://forums.adobe.com/message/1944754#1944754
	app.activeDocument.activeLayer = theLayer;
	//Assumes activeDocument and activeLayer
		var ref = new ActionReference();
		ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
		d = executeActionGet(ref);
	return d.getInteger(charIDToTypeID('LyrI'));
};
////// load transparency, ontersect with layer mask ofd another layer, add layer mask //////
function intersectedLayerMask (layerID) {
	var idChnl = charIDToTypeID( "Chnl" );
	// =======================================================
	var idsetd = charIDToTypeID( "setd" );
		var desc2 = new ActionDescriptor();
		var idnull = charIDToTypeID( "null" );
			var ref1 = new ActionReference();
			var idfsel = charIDToTypeID( "fsel" );
			ref1.putProperty( idChnl, idfsel );
		desc2.putReference( idnull, ref1 );
		var idT = charIDToTypeID( "T   " );
			var ref2 = new ActionReference();
			var idTrsp = charIDToTypeID( "Trsp" );
			ref2.putEnumerated( idChnl, idChnl, idTrsp );
		desc2.putReference( idT, ref2 );
	executeAction( idsetd, desc2, DialogModes.NO );
	// =======================================================
	var idIntr = charIDToTypeID( "Intr" );
		var desc3 = new ActionDescriptor();
		var idnull = charIDToTypeID( "null" );
			var ref3 = new ActionReference();
			var idMsk = charIDToTypeID( "Msk " );
			ref3.putEnumerated( idChnl, idChnl, idMsk );
			var idLyr = charIDToTypeID( "Lyr " );
			ref3.putIdentifier( idLyr, layerID );
		desc3.putReference( idnull, ref3 );
		var idWith = charIDToTypeID( "With" );
			var ref4 = new ActionReference();
			var idfsel = charIDToTypeID( "fsel" );
			ref4.putProperty( idChnl, idfsel );
		desc3.putReference( idWith, ref4 );
	executeAction( idIntr, desc3, DialogModes.NO );
	// =======================================================
	var idMk = charIDToTypeID( "Mk  " );
		var desc4 = new ActionDescriptor();
		var idNw = charIDToTypeID( "Nw  " );
		desc4.putClass( idNw, idChnl );
		var idAt = charIDToTypeID( "At  " );
			var ref5 = new ActionReference();
			var idMsk = charIDToTypeID( "Msk " );
			ref5.putEnumerated( idChnl, idChnl, idMsk );
		desc4.putReference( idAt, ref5 );
		var idUsng = charIDToTypeID( "Usng" );
		var idUsrM = charIDToTypeID( "UsrM" );
		var idRvlS = charIDToTypeID( "RvlS" );
		desc4.putEnumerated( idUsng, idUsrM, idRvlS );
	executeAction( idMk, desc4, DialogModes.NO );
};

 

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