What's new

Batch Automation Add banner at the top of the layer


Swisfa

New Member
Messages
1
Likes
0
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:
text banner large size.jpg
Photo:
0.jpg
Result:
0.jpg
The script I'm using:

// FIT LAYER TO CANVAS

// via https://forums.adobe.com/message/5413957#5413957

// https://gist.githubusercontent.com/jawinn/ab4df1c33d0743e41fd3/raw/72ff297ae42ed029c86be7644bd021ef4...

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:

example.jpg

Any help I will appreciate it.

Thank you.
 

polarwoc

Guru
Messages
961
Likes
743
The script I'm using:
Hi @Swisfa I would like to assist if I can.

Looking at the script you posted, I do not see a call to function FitLayerToCanvas(keepAspect).

Is it possible that you did not paste the full script?

There is no reference to the banner file name and path in the script. How are you executing the script?
 

Top