Skip to main content
Participant
February 24, 2020
Question

Photoshop

  • February 24, 2020
  • 2 replies
  • 351 views

.

This topic has been closed for replies.

2 replies

Stephen Marsh
Community Expert
Community Expert
February 25, 2020

Comparing the AM code recorded by script listener and clean SL from a crop created with and without the "Delete cropped pixels" option, this command does appear to be recorded as either true or false, which is shown in the code posted by JJMack.

 

 

JJMack
Community Expert
Community Expert
February 24, 2020

Perhaps this will help.  I used the Scriptlistener Plug-in to record a crop that does not delete pixels and then used  cleans SL to changes the action manager code into a function. See if the function work for you.  Note: Crop does not invole itepolation Pixels are either deleted or masked the images is not resized. Note the crop I did  was also not constrained.  I have no Idea if you want to do a constrained Crop If the Top Left bottom Right need to be set accordingly,  The function seems the have a Boolean option for constrainProportions. Note Rotation is also supported to straighten.

 

 

// =======================================================
crop(224, 156, 2672, 2576, 0, false, false);
function crop(top, left, bottom, right, angle, delete2, constrainProportions) {
	var descriptor = new ActionDescriptor();
	var descriptor2 = new ActionDescriptor();

	descriptor2.putUnitDouble( stringIDToTypeID( "top" ), stringIDToTypeID( "distanceUnit" ), top );
	descriptor2.putUnitDouble( stringIDToTypeID( "left" ), stringIDToTypeID( "distanceUnit" ), left );
	descriptor2.putUnitDouble( stringIDToTypeID( "bottom" ), stringIDToTypeID( "distanceUnit" ), bottom );
	descriptor2.putUnitDouble( stringIDToTypeID( "right" ), stringIDToTypeID( "distanceUnit" ), right );
	descriptor.putObject( stringIDToTypeID( "to" ), stringIDToTypeID( "rectangle" ), descriptor2 );
	descriptor.putUnitDouble( stringIDToTypeID( "angle" ), stringIDToTypeID( "angleUnit" ), angle );
	descriptor.putBoolean( stringIDToTypeID( "delete" ), delete2 );
	descriptor.putEnumerated( stringIDToTypeID( "cropAspectRatioModeKey" ), stringIDToTypeID( "cropAspectRatioModeClass" ), stringIDToTypeID( "pureAspectRatio" ));
	descriptor.putBoolean( stringIDToTypeID( "constrainProportions" ), constrainProportions );
	executeAction( stringIDToTypeID( "crop" ), descriptor, DialogModes.NO );
}

 

 

 

 

 

 

JJMack
JJMack
Community Expert
Community Expert
February 24, 2020

I not sure about the bounds and constrained in the action manager function.  For with DOM code it looks like you may able to force constrain by specifying the crop's remaining width or height.  To me the seems to indicate that the top left point may be use then the angle  and specified width  or height use to calculate the point for the width of height then the remaining point set to maintain the document current aspect ratio for the DOM method. 

 

The thing is with the ActionManger Crop Function  Clean SL created I see no way to specify the crop width or height other than the bounds the top left bottom right points. There is no Crop Width or Crop Height parameters.  However there seems to be a constrainproportions option.

JJMack
JJMack
Community Expert
Community Expert
February 24, 2020

With Content Aware constrainProportions can instead becone autofill.

crop(376, 208, 3024, 2488, 0, false, true);
function crop(top, left, bottom, right, angle, delete2, autoFill) {
	var descriptor = new ActionDescriptor();
	var descriptor2 = new ActionDescriptor();

	descriptor2.putUnitDouble( stringIDToTypeID( "top" ), stringIDToTypeID( "distanceUnit" ), top );
	descriptor2.putUnitDouble( stringIDToTypeID( "left" ), stringIDToTypeID( "distanceUnit" ), left );
	descriptor2.putUnitDouble( stringIDToTypeID( "bottom" ), stringIDToTypeID( "distanceUnit" ), bottom );
	descriptor2.putUnitDouble( stringIDToTypeID( "right" ), stringIDToTypeID( "distanceUnit" ), right );
	descriptor.putObject( stringIDToTypeID( "to" ), stringIDToTypeID( "rectangle" ), descriptor2 );
	descriptor.putUnitDouble( stringIDToTypeID( "angle" ), stringIDToTypeID( "angleUnit" ), angle );
	descriptor.putBoolean( stringIDToTypeID( "delete" ), delete2 );
	descriptor.putBoolean( stringIDToTypeID( "autoFill" ), autoFill );
	descriptor.putEnumerated( stringIDToTypeID( "cropAspectRatioModeKey" ), stringIDToTypeID( "cropAspectRatioModeClass" ), stringIDToTypeID( "targetSize" ));
	executeAction( stringIDToTypeID( "crop" ), descriptor, DialogModes.NO );
}
JJMack