Copy link to clipboard
Copied
Hi guys, This is my first thread, I'm new to this forum and I've found some very useful tips inside.
I have like 700 images and I want to do batch processing on them by adding a banner at the top, I've already found a script but he just fit the banner inside the layer this is an example.
Banner:
Photo:
Result:
The script I'm using:
// FIT LAYER TO CANVAS
// via https://forums.adobe.com/message/5413957#5413957
// https://gist.github.com/jawinn/ab4df1c33d0743e41fd3
var maintainAspectRatio = true; // set to true to keep aspect ratio, false to stretch/distort to fit
if(app.documents.length>0){
app.activeDocument.suspendHistory ('Fit Layer to Canvas', 'FitLayerToCanvas('+maintainAspectRatio+')');
}
function FitLayerToCanvas( keepAspect ){// keepAspect:Boolean - optional. Default to false
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;
var width = doc.width.as('px');
var height =doc.height.as('px');
var bounds = app.activeDocument.activeLayer.bounds;
var layerWidth = bounds[2].as('px')-bounds[0].as('px');
var layerHeight = bounds[3].as('px')-bounds[1].as('px');
// move the layer so top left corner matches canvas top left corner
layer.translate(new UnitValue(0-layer.bounds[0].as('px'),'px'), new UnitValue(0-layer.bounds[1].as('px'),'px'));
if( !keepAspect ){
// scale the layer to match canvas
layer.resize( (width/layerWidth)*100,(height/layerHeight)*100,AnchorPosition.TOPLEFT);
}else{
var layerRatio = layerWidth / layerHeight;
var newWidth = width;
var newHeight = ((1.0 * width) / layerRatio);
if (newHeight >= height) {
newWidth = layerRatio * height;
newHeight = height;
}
var resizePercent = newWidth/layerWidth*100;
app.activeDocument.activeLayer.resize(resizePercent,resizePercent,AnchorPosition.TOPLEFT);
}
// restore the ruler
app.preferences.rulerUnits = defaultRulerUnits;
}
As you can see the banner insert and fit inside at the top of the layer.
But what I'm trying to do right now is to increase the canvas space and insert the banner at the top of the layer and I don't have any idea to do it.
I want it to look like this:
Any help I will appreciate it.
Thank you.
So you can add this code right before your last line of code where you're resetting the ruler preferences:
var doc = activeDocument;
app.preferences.rulerUnits = Units.PIXELS;
var layerH = doc.activeLayer.bounds[3]
var extendHeight = doc.height + layerH;
canvas ();
doc.activeLayer.translate(0,-layerH);
function canvas(){
var idCnvS = charIDToTypeID( "CnvS" );
var desc303 = new ActionDescriptor();
var idHght = charIDToTypeID( "Hght" );
var idPxl = charIDToTypeID( "#P
...
Copy link to clipboard
Copied
If your images are all the same size, aspect ratio and print resolution. If you do not know Photoshop Scripting you can record an action that add canvas to the top of your image document. Then place in your banner and align the layer to the canvas top left. The batch the action. Or you can create a Photo collage template PSD file for your composite image with the banned and use a script you download from the web to batch populate your images into the template.
Copy link to clipboard
Copied
Thank you for your fast reply. but this is the problem the images are not all the same size!
Copy link to clipboard
Copied
Probably the easiest would be let your existing script run and place the banner. You can record the code for expanding the canvas with scriptListener. When you do, make sure to set the anchor point bottom center. So then all you have to do is get the doc height by using activeDocument.height, and get the banner height. Since it's at the top, you just need to use activeLayer.bounds[3]. Add those two numbers together and plug the result in the canvas resize that you recorded. Then translate the banner layer to the top of the canvas.
Copy link to clipboard
Copied
So you can add this code right before your last line of code where you're resetting the ruler preferences:
var doc = activeDocument;
app.preferences.rulerUnits = Units.PIXELS;
var layerH = doc.activeLayer.bounds[3]
var extendHeight = doc.height + layerH;
canvas ();
doc.activeLayer.translate(0,-layerH);
function canvas(){
var idCnvS = charIDToTypeID( "CnvS" );
var desc303 = new ActionDescriptor();
var idHght = charIDToTypeID( "Hght" );
var idPxl = charIDToTypeID( "#Pxl" );
desc303.putUnitDouble( idHght, idPxl, extendHeight );
var idVrtc = charIDToTypeID( "Vrtc" );
var idVrtL = charIDToTypeID( "VrtL" );
var idBttm = charIDToTypeID( "Bttm" );
desc303.putEnumerated( idVrtc, idVrtL, idBttm );
var idcanvasExtensionColorType = stringIDToTypeID( "canvasExtensionColorType" );
var idcanvasExtensionColorType = stringIDToTypeID( "canvasExtensionColorType" );
var idWht = charIDToTypeID( "Wht " );
desc303.putEnumerated( idcanvasExtensionColorType, idcanvasExtensionColorType, idWht );
executeAction( idCnvS, desc303, DialogModes.NO );
}
Copy link to clipboard
Copied
Thank you soooooo much, it's working !!!!!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now