我一直试图确定一个脚本以用于数百个图像。这个论坛非常有用,我正尝试修改JJMack的画布脚本。
我正在尝试使脚本执行此操作...
1-如果该图层比画布宽且高,请不要更改它。
2-如果该图层的宽度小于画布,但不如画布高,则按比例缩放以适合画布宽度
3-如果该层比画布宽但不比画布高,则按比例缩放它以适合画布高度
4-然后,如果图层已被点2或3缩放,则将其居中放置在画布上。
这种脚本可以工作,但是我发现如果该层既不那么宽又不那么高,它似乎会缩放该层两次-使其变得比所需的更大。
我想知道是否有人会帮助我找出解决方案?
非常感谢,J
var SHeight = app.activeDocument.height.as('px');
var bounds = app.activeDocument.activeLayer.bounds;
var LWidth = bounds[2].as('px')-bounds[0].as('px');
var LHeight = bounds[3].as('px')-bounds[1].as('px');
var userResampleMethod = app.preferences.interpolation; // Save interpolation settings
app.preferences.interpolation = ResampleMethod.BICUBIC; // resample interpolation bicubic
// ------------------------------------------------------------------------------------------
// If layer width or height less than canvas,scale to fit 1% larger
// ------------------------------------------------------------------------------------------
if (LWidth<SWidth) { // Smart Object layer Aspect Ratio less the Canvas area Aspect Ratio
var percentageChange = ((SWidth/LWidth)*101); // Resize to canvas area width slightly larger
activeDocument.activeLayer.resize(percentageChange,percentageChange,AnchorPosition.MIDDLECENTER);
app.preferences.interpolation = userResampleMethod; // Reset interpolation setting
app.preferences.interpolation = userResampleMethod; // Reset interpolation setting
app.activeDocument.selection.selectAll();
align('AdCH'); align('AdCV');
app.activeDocument.selection.deselect();
// -----------------------------------------
// Align Layers to selection
// -----------------------------------------
function align(method) {
var desc = new actionDescriptor();
var ref = new actionReference();
ref.putEnumerated( charIDToTypeID( "Lyr " ),charIDToTypeID( "Ordn" ),charIDToTypeID( "Trgt" ) );
desc.putReference( charIDToTypeID( "null" ),ref );
desc.putEnumerated( charIDToTypeID( "Usng" ),charIDToTypeID( "ADSt" ),charIDToTypeID( method ) );
try{
executeaction( charIDToTypeID( "Algn" ),desc,DialogModes.NO );
}catch(e){}
}}
if (LHeight<SHeight) { // Smart Object layer Aspect Ratio less the Canvas area Aspect Ratio
var percentageChange = ((SHeight/LHeight)*101); // Resize to canvas area width slightly larger
activeDocument.activeLayer.resize(percentageChange,AnchorPosition.MIDDLECENTER);
app.preferences.interpolation = userResampleMethod; // Reset interpolation setting
app.activeDocument.selection.selectAll();
align('AdCH'); align('AdCV');
app.activeDocument.selection.deselect();
// -----------------------------------------
// Align Layers to selection
// -----------------------------------------
function align(method) {
var desc = new actionDescriptor();
var ref = new actionReference();
ref.putEnumerated( charIDToTypeID( "Lyr " ),DialogModes.NO );
}catch(e){}
}}