resize layer 1 with the dimension of the background image
i need to resize layer 1 to the same size as the background, automatically.
I tried with actions, but it doesn't work, how to make a script?
i need to resize layer 1 to the same size as the background, automatically.
I tried with actions, but it doesn't work, how to make a script?
Here is a simple script to distort the active layer to match the canvas. The layer to resize needs to be pre-selected/targeted in the layers panel before running the script. When recording the action you can use an absolute/explicit selection of "Layer 1" or you can use a relative keyboard shortcut to select the uppermost layer opt/alt . (dot/period character):
//community.adobe.com/t5/photoshop/scale-layer-to-current-canvas-size-photoshop/td-p/5217315
// Michael L Hale
function main() {
var doc = app.activeDocument;
var layer = doc.activeLayer;
layer.translate(new UnitValue(0 - layer.bounds[0].as('px'), 'px'), new UnitValue(0 - layer.bounds[1].as('px'), 'px'));
layer.resize((doc.width.value / (layer.bounds[2] - layer.bounds[0])) * 100, (doc.height.value / (layer.bounds[3] - layer.bounds[1])) * 100, AnchorPosition.TOPLEFT);
}
app.activeDocument.suspendHistory('Resize Layer to Canvas', 'main()');
EDIT: This variation will select the layer named "Layer 1":
function main() {
var doc = app.activeDocument;
doc.activeLayer = doc.layers.getByName("Layer 1");
var layer = doc.activeLayer;
layer.translate(new UnitValue(0 - layer.bounds[0].as('px'), 'px'), new UnitValue(0 - layer.bounds[1].as('px'), 'px'));
layer.resize((doc.width.value / (layer.bounds[2] - layer.bounds[0])) * 100, (doc.height.value / (layer.bounds[3] - layer.bounds[1])) * 100, AnchorPosition.TOPLEFT);
}
app.activeDocument.suspendHistory('Resize Layer to Canvas', 'main()');
You can record the script into an action as a step.
https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html
EDIT: And here is another script that achieves the same result:
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.