I was testing yesterday with a portrait oriented image (taller than wide ) and a square shaped background image and it worked great.
This afternoon I finished integrating the script into my resize script and tried to use it on a landscape oriented image (wider than tall) and the same background images. The fill function appears to only fill vertically. I got white space to the left and right of the background image.
Place image behind current image and resize to fill bg?
-
christopherjohnson
Place image behind current image and resize to fill bg?
I'll try to find some other way to do it.
-
Mike Hale
Place image behind current image and resize to fill bg?
Sorry, I forgot about this. I will see if I can come up with a fix or a different way to fill.
-
Mike Hale
Place image behind current image and resize to fill bg?
This seems to work both scaling up or down regardless of aspect ratio differences.
Code: Select allfunction fillLayerToCanvas( ){
var doc = app.activeDocument;
var layer = doc.activeLayer;
// do nothing if layer is background or locked
if(layer.isBackgroundLayer || layer.allLocked || layer.pixelsLocked
|| layer.positionLocked || layer.transparentPixelsLocked ) return;
// do nothing if layer is not normal artLayer or Smart Object
if( layer.kind != LayerKind.NORMAL && layer.kind != LayerKind.SMARTOBJECT) return;
// store the ruler
var defaultRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// make sure layer is centered
doc.selection.selectAll();
alignCenter();
doc.selection.deselect();
var width = doc.width.as('px');
var height =doc.height.as('px');
var bounds = layer.bounds;
var layerWidth = bounds[2].as('px')-bounds[0].as('px');
var layerHeight = bounds[3].as('px')-bounds[1].as('px');
var widthPercent = ((width/layerWidth)*100)+1;
var heightPercent = ((height/layerHeight)*100)+1;
var scaleUp = Math.min(widthPercent,heightPercent) < 100;
if(scaleUp){
layer.resize(Math.max(widthPercent,heightPercent),Math.max(widthPercent,heightPercent),AnchorPosition.MIDDLECENTER);
}else{
layer.resize(Math.min(widthPercent,heightPercent),Math.min(widthPercent,heightPercent),AnchorPosition.MIDDLECENTER);
}
// restore the ruler
app.preferences.rulerUnits = defaultRulerUnits;
};
function align(type){
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Lnkd" ));
desc.putReference( charIDToTypeID( "null" ), ref);
desc.putEnumerated( charIDToTypeID( "Usng" ),charIDToTypeID( "ADSt" ), charIDToTypeID( type ) );
executeAction( charIDToTypeID( "Algn" ), desc, DialogModes.NO );;
};
function alignCenter(){
align("AdCH");
align("AdCV");
};
fillLayerToCanvas( );
Code: Select allfunction fillLayerToCanvas( ){
var doc = app.activeDocument;
var layer = doc.activeLayer;
// do nothing if layer is background or locked
if(layer.isBackgroundLayer || layer.allLocked || layer.pixelsLocked
|| layer.positionLocked || layer.transparentPixelsLocked ) return;
// do nothing if layer is not normal artLayer or Smart Object
if( layer.kind != LayerKind.NORMAL && layer.kind != LayerKind.SMARTOBJECT) return;
// store the ruler
var defaultRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// make sure layer is centered
doc.selection.selectAll();
alignCenter();
doc.selection.deselect();
var width = doc.width.as('px');
var height =doc.height.as('px');
var bounds = layer.bounds;
var layerWidth = bounds[2].as('px')-bounds[0].as('px');
var layerHeight = bounds[3].as('px')-bounds[1].as('px');
var widthPercent = ((width/layerWidth)*100)+1;
var heightPercent = ((height/layerHeight)*100)+1;
var scaleUp = Math.min(widthPercent,heightPercent) < 100;
if(scaleUp){
layer.resize(Math.max(widthPercent,heightPercent),Math.max(widthPercent,heightPercent),AnchorPosition.MIDDLECENTER);
}else{
layer.resize(Math.min(widthPercent,heightPercent),Math.min(widthPercent,heightPercent),AnchorPosition.MIDDLECENTER);
}
// restore the ruler
app.preferences.rulerUnits = defaultRulerUnits;
};
function align(type){
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Lnkd" ));
desc.putReference( charIDToTypeID( "null" ), ref);
desc.putEnumerated( charIDToTypeID( "Usng" ),charIDToTypeID( "ADSt" ), charIDToTypeID( type ) );
executeAction( charIDToTypeID( "Algn" ), desc, DialogModes.NO );;
};
function alignCenter(){
align("AdCH");
align("AdCV");
};
fillLayerToCanvas( );
-
christopherjohnson
Place image behind current image and resize to fill bg?
Thank you. I'll be testing it this week