Skip to main content
Known Participant
March 31, 2021
Question

How to automate cropping with a data file?

  • March 31, 2021
  • 2 replies
  • 863 views

I have a data file with image names, and cropping coordinates (X,Y,W,H) for a varying number of specific crops for each image in the list. I'm looking for a way to automate the process of placing the crop and saving the cropped image as a new file. Any help would be appreciated.

This topic has been closed for replies.

2 replies

Chuck Uebele
Community Expert
Community Expert
March 31, 2021

Yep, should be pretty easy with a script. You can use scriptListener to record the code for cropping, then just use a variable to change the values from your data sheet.

Known Participant
April 12, 2021

Thank you, are you aware of any experienced script writers that may be interested in fee based renumeration for writing this script and others?

Chuck Uebele
Community Expert
Community Expert
April 12, 2021

I would send a PM to either @Kukurykus  or @r-bin .

JJMack
Community Expert
Community Expert
March 31, 2021

You  would need to learn Photoshop Scripting. Then you could write a Photoshop script that will read your data file, open the image files crop them and save output image files to some output folder. With  (X,Y,W,H)  it is easy to set a selection( ( X,Y),(X+W,Y),(X+W,Y+H), (X,Y+H)) and use] image crop.

JJMack
JJMack
Community Expert
Community Expert
March 31, 2021
var strtRulerUnits = app.preferences.rulerUnits;	// Save Users ruler units 
app.preferences.rulerUnits = Units.PIXELS;			// work with pixels 

var x = 10;
var y = 10;
var width = 100;
var height = 100;

var cropArea = Array(Array(x,y), Array(x+width,y), Array(x+width,y+height), Array(x,y+height));
app.activeDocument.selection.select(cropArea); 
crop(true);
app.activeDocument.selection.deselect();

app.preferences.rulerUnits = strtRulerUnits;		// Restore user ruler units 


////// Helper functions //////
function crop(delete2) {
	var descriptor = new ActionDescriptor();
	descriptor.putBoolean( stringIDToTypeID( "delete" ), delete2 );
	executeAction( stringIDToTypeID( "crop" ), descriptor, DialogModes.NO );
}
JJMack
Known Participant
April 12, 2021

My apologies for the delay on this response, unexpected family issue distracted me, can you recommend some tutorials to get my script learning going in the right place for this specific type of function?