Participant
June 22, 2021
Answered
Select Subject trim to the center ratio 3:4 Keep Background
- June 22, 2021
- 3 replies
- 1480 views
Me again.
Another issue.
How do I center this kind of images to a ratio 3:4 keeping the backround color.
I found this script here : and it's working in terms of centering the image but it leaves an empty line on the right of the image...
#target photoshop
var oldPref = app.preferences.rulerUnits;//stores old measurement preferences so that they can be reset when the script is done.
app.preferences.rulerUnits = Units.PIXELS;
var doc = activeDocument;
selSub ();
var cropBounds = doc.selection.bounds;
var vertLength = parseInt(cropBounds[3]-cropBounds[1]);
var horLength = parseInt(cropBounds[2]-cropBounds[0]);
var cRatio = 3/4;
var horPad = ((vertLength*cRatio) - horLength)/2;
doc.selection.deselect();
cropImg ();
app.preferences.rulerUnits = oldPref;
function selSub(){
var idautoCutout = stringIDToTypeID( "autoCutout" );
var desc4 = new ActionDescriptor();
var idsampleAllLayers = stringIDToTypeID( "sampleAllLayers" );
desc4.putBoolean( idsampleAllLayers, false );
executeAction( idautoCutout, desc4, DialogModes.NO );
};
function cropImg(){
var idCrop = charIDToTypeID( "Crop" );
var desc4 = new ActionDescriptor();
var idT = charIDToTypeID( "T " );
var desc5 = new ActionDescriptor();
var idTop = charIDToTypeID( "Top " );
var idPxl = charIDToTypeID( "#Pxl" );
desc5.putUnitDouble( idTop, idPxl, cropBounds[1] );
var idLeft = charIDToTypeID( "Left" );
var idPxl = charIDToTypeID( "#Pxl" );
desc5.putUnitDouble( idLeft, idPxl, cropBounds[0]-horPad );
var idBtom = charIDToTypeID( "Btom" );
var idPxl = charIDToTypeID( "#Pxl" );
desc5.putUnitDouble( idBtom, idPxl, cropBounds[3] );
var idRght = charIDToTypeID( "Rght" );
var idPxl = charIDToTypeID( "#Pxl" );
desc5.putUnitDouble( idRght, idPxl, cropBounds[2]+horPad );
var idRctn = charIDToTypeID( "Rctn" );
desc4.putObject( idT, idRctn, desc5 );
var idAngl = charIDToTypeID( "Angl" );
var idAng = charIDToTypeID( "#Ang" );
desc4.putUnitDouble( idAngl, idAng, 0.000000 );
var idDlt = charIDToTypeID( "Dlt " );
desc4.putBoolean( idDlt, false );
var idcropAspectRatioModeKey = stringIDToTypeID( "cropAspectRatioModeKey" );
var idcropAspectRatioModeClass = stringIDToTypeID( "cropAspectRatioModeClass" );
var idunconstrained = stringIDToTypeID( "unconstrained" );
desc4.putEnumerated( idcropAspectRatioModeKey, idcropAspectRatioModeClass, idunconstrained );
executeAction( idCrop, desc4, DialogModes.NO );
};
