This script automates many of the repetitive tasks involved in creating transitions and setting up a composition, letting you focus on adjusting creative parameters as needed.
JavaScript
// After Effects Script: Enhanced Slideshow Creator with Consistent Overlap for All Transitions
if (app.project.selection.length > 0) {
function createSlideshow() {
// Create the UI
var dialog = new Window("dialog", "Slideshow Settings");
dialog.orientation = "column";
dialog.alignChildren = "left";
// Duration settings
dialog.add("statictext", undefined, "Slide Duration (seconds):");
var slideDurationInput = dialog.add("edittext", undefined, "3");
slideDurationInput.size = [200, 25];
dialog.add("statictext", undefined, "In Duration (seconds):");
var inDurationInput = dialog.add("edittext", undefined, "1");
inDurationInput.size = [200, 25];
dialog.add("statictext", undefined, "Out Duration (seconds):");
var outDurationInput = dialog.add("edittext", undefined, "1");
outDurationInput.size = [200, 25];
dialog.add("statictext", undefined, "Overlap Duration (seconds):"); // New Overlap Duration input
var overlapDurationInput = dialog.add("edittext", undefined, "0.5");
overlapDurationInput.size = [200, 25];
// Effects dropdown with new options
dialog.add("statictext", undefined, "Transition Effect:");
var effectDropdown = dialog.add("dropdownlist", undefined, [
"None",
"Smooth Zoom In",
"Smooth Zoom Out",
"Opacity Fade",
"Slide Left",
"Slide Right",
"Rotate In",
"Rotate Out",
"Zoom and Rotate",
"Opacity and Zoom In",
"Opacity and Zoom Out",
"Slide Up",
"Slide Down",
"Blur In",
"Blur Out"
]);
effectDropdown.selection = 0;
// Customizable Zoom and Blur Controls
dialog.add("statictext", undefined, "Zoom Amount (Start % / End %):");
var zoomStartInput = dialog.add("edittext", undefined, "90");
var zoomEndInput = dialog.add("edittext", undefined, "100");
zoomStartInput.size = zoomEndInput.size = [90, 25];
dialog.add("statictext", undefined, "Blur Amount:");
var blurAmountInput = dialog.add("edittext", undefined, "50");
blurAmountInput.size = [200, 25];
// Buttons
var buttonGroup = dialog.add("group");
buttonGroup.orientation = "row";
var okButton = buttonGroup.add("button", undefined, "Create Slideshow");
var cancelButton = buttonGroup.add("button", undefined, "Cancel");
// When OK is clicked
okButton.onClick = function () {
var slideDuration = parseFloat(slideDurationInput.text) || 3;
var inDuration = parseFloat(inDurationInput.text) || 1;
var outDuration = parseFloat(outDurationInput.text) || 1;
var overlapDuration = parseFloat(overlapDurationInput.text) || 0.5;
var effect = effectDropdown.selection.text;
var zoomStart = parseFloat(zoomStartInput.text) || 90;
var zoomEnd = parseFloat(zoomEndInput.text) || 100;
var blurAmount = parseFloat(blurAmountInput.text) || 50;
app.beginUndoGroup("Create Enhanced Slideshow");
var comp = app.project.activeItem;
if (!(comp instanceof CompItem)) {
comp = app.project.items.addComp("Enhanced Slideshow", 1920, 1080, 1, (slideDuration + inDuration + outDuration) * app.project.selection.length, 30);
}
// Track previous layer's end time for overlap calculation
var previousEndTime = 0;
// Process each selected image with overlap
var images = app.project.selection;
for (var i = 0; i < images.length; i++) {
var imageLayer = comp.layers.add(images[i]);
// Calculate start time with overlap based on previous layer's end time
var startTime = previousEndTime - overlapDuration;
imageLayer.startTime = startTime;
// Fit image to comp based on exact width or height match and get base scale
var baseScale = fitLayerToCompWidthOrHeight(imageLayer, comp);
var inPoint = imageLayer.startTime;
var outPoint = inPoint + slideDuration;
// Apply effect and adjust end time to allow overlapping
applyEffect(imageLayer, inDuration, outDuration, effect, inPoint, outPoint, baseScale, zoomStart, zoomEnd, blurAmount, overlapDuration);
// Set the layer's out point to match the end of the duration
imageLayer.outPoint = outPoint;
// Update previousEndTime for the next layer
previousEndTime = outPoint;
}
// Set end of work area and open the comp
comp.workAreaDuration = comp.duration;
comp.openInViewer(); // Open the comp in the viewer
app.endUndoGroup();
dialog.close();
};
// Cancel button action
cancelButton.onClick = function () {
dialog.close();
};
dialog.show();
}
// Function to scale layer to match either the comp's width or height, returns base scale for 100%
function fitLayerToCompWidthOrHeight(layer, comp) {
var layerWidth = layer.source.width;
var layerHeight = layer.source.height;
var compWidth = comp.width;
var compHeight = comp.height;
// Calculate scale factors to match either width or height
var scaleToFitWidth = (compWidth / layerWidth) * 100;
var scaleToFitHeight = (compHeight / layerHeight) * 100;
// Use the larger scale factor to ensure the image covers the entire comp
var finalScale = Math.max(scaleToFitWidth, scaleToFitHeight);
layer.property("Scale").setValue([finalScale, finalScale]);
return finalScale;
}
// Function to apply the selected effect with customizable zoom, blur, and overlap
function applyEffect(layer, inDuration, outDuration, effect, inTime, outTime, baseScale, zoomStart, zoomEnd, blurAmount, overlapDuration) {
var endTime = outTime; // End time of the layer's duration for proper keyframes
if (effect === "Opacity Fade" || overlapDuration > 0) {
layer.opacity.setValueAtTime(inTime, 0);
layer.opacity.setValueAtTime(inTime + inDuration, 100);
layer.opacity.setValueAtTime(endTime - outDuration, 100);
layer.opacity.setValueAtTime(endTime, 0);
}
if (effect === "Smooth Zoom In") {
layer.scale.setValueAtTime(inTime, [baseScale * (zoomStart / 100), baseScale * (zoomStart / 100)]);
layer.scale.setValueAtTime(endTime, [baseScale * (zoomEnd / 100), baseScale * (zoomEnd / 100)]);
} else if (effect === "Smooth Zoom Out") {
layer.scale.setValueAtTime(inTime, [baseScale * (zoomEnd / 100), baseScale * (zoomEnd / 100)]);
layer.scale.setValueAtTime(endTime, [baseScale * (zoomStart / 100), baseScale * (zoomStart / 100)]);
} else if (effect === "Opacity and Zoom In") {
layer.opacity.setValueAtTime(inTime, 0);
layer.opacity.setValueAtTime(inTime + inDuration, 100);
layer.scale.setValueAtTime(inTime, [baseScale * (zoomStart / 100), baseScale * (zoomStart / 100)]);
layer.scale.setValueAtTime(endTime, [baseScale * (zoomEnd / 100), baseScale * (zoomEnd / 100)]);
} else if (effect === "Opacity and Zoom Out") {
layer.opacity.setValueAtTime(endTime - outDuration, 100);
layer.opacity.setValueAtTime(endTime, 0);
layer.scale.setValueAtTime(inTime, [baseScale * (zoomEnd / 100), baseScale * (zoomEnd / 100)]);
layer.scale.setValueAtTime(endTime, [baseScale * (zoomStart / 100), baseScale * (zoomStart / 100)]);
} else if (effect === "Slide Left") {
var compWidth = app.project.activeItem.width;
layer.position.setValueAtTime(inTime, [-compWidth / 2, layer.position.value[1]]);
layer.position.setValueAtTime(inTime + inDuration, [compWidth / 2, layer.position.value[1]]);
} else if (effect === "Slide Right") {
var compWidth = app.project.activeItem.width;
layer.position.setValueAtTime(inTime, [compWidth * 1.5, layer.position.value[1]]);
layer.position.setValueAtTime(inTime + inDuration, [compWidth / 2, layer.position.value[1]]);
} else if (effect === "Rotate In") {
layer.rotation.setValueAtTime(inTime, -15);
layer.rotation.setValueAtTime(inTime + inDuration, 0);
} else if (effect === "Rotate Out") {
layer.rotation.setValueAtTime(endTime - outDuration, 0);
layer.rotation.setValueAtTime(endTime, 15);
} else if (effect === "Zoom and Rotate") {
layer.scale.setValueAtTime(inTime, [baseScale * (zoomStart / 100), baseScale * (zoomStart / 100)]);
layer.scale.setValueAtTime(endTime, [baseScale * (zoomEnd / 100), baseScale * (zoomEnd / 100)]);
layer.rotation.setValueAtTime(inTime, -10);
layer.rotation.setValueAtTime(endTime, 10);
} else if (effect === "Slide Up") {
var compHeight = app.project.activeItem.height;
layer.position.setValueAtTime(inTime, [layer.position.value[0], compHeight * 1.5]);
layer.position.setValueAtTime(inTime + inDuration, [layer.position.value[0], compHeight / 2]);
} else if (effect === "Slide Down") {
var compHeight = app.project.activeItem.height;
layer.position.setValueAtTime(inTime, [layer.position.value[0], -compHeight / 2]);
layer.position.setValueAtTime(inTime + inDuration, [layer.position.value[0], compHeight / 2]);
} else if (effect === "Blur In") {
var blurEffect = layer.property("Effects").addProperty("ADBE Gaussian Blur 2");
blurEffect.property("Blurriness").setValueAtTime(inTime, blurAmount);
blurEffect.property("Blurriness").setValueAtTime(inTime + inDuration, 0);
} else if (effect === "Blur Out") {
var blurEffect = layer.property("Effects").addProperty("ADBE Gaussian Blur 2");
blurEffect.property("Blurriness").setValueAtTime(endTime - outDuration, 0);
blurEffect.property("Blurriness").setValueAtTime(endTime, blurAmount);
}
}
createSlideshow();
} else {
alert("Please select multiple images from the Project panel.");
}
Usage:
To use the script, follow these steps:
- In your After Effects project, select multiple images from the Project panel.
- Run the script (usually via File > Scripts or by executing it in your script editor).
- The “Slideshow Settings” dialog will open. Configure the settings as needed: • Enter your desired durations for each slide as well as transition in and out times. • Set the desired overlap duration for consistent slide overlap. • Choose the transition effect from the dropdown menu. • Optionally, adjust the zoom percentages and the blur amount if the chosen effect supports these options.
- Click the “Create Slideshow” button: • The script will automatically create or update a composition. • It will add each selected image as a layer, applying the chosen transitions and overlap between slides. • The composition work area is set based on the combined duration of your slides, ensuring the entire slideshow is previewable.
- If you change your mind or want to exit without applying the changes, click “Cancel”.