Created
April 28, 2022 04:54
-
-
Save david-littlefield/33b2cbda3df5511b7628e3e82324ec19 to your computer and use it in GitHub Desktop.
[Automatically Center Logo, Title, and Subtitle] Centers logo, title, and subtitle based on whether logo, title, or subtitle is hidden. #after_effects #scale #center #position #horizontal #vertical #logo #title #subtitle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var extra_horizontal_margin_composition = comp("Preview"); | |
var extra_horizontal_margin_layer = extra_horizontal_margin_composition.layer("Controller - All Objects"); | |
var extra_horizontal_margin_effect = extra_horizontal_margin_layer.effect("Extra Horizontal Margin"); | |
var extra_horizontal_margin_slider = extra_horizontal_margin_effect("Slider"); | |
var extra_vertical_margin_composition = comp("Preview"); | |
var extra_vertical_margin_layer = extra_vertical_margin_composition.layer("Controller - All Objects"); | |
var extra_vertical_margin_effect = extra_vertical_margin_layer.effect("Extra Vertical Margin"); | |
var extra_vertical_margin_slider = extra_vertical_margin_effect("Slider"); | |
var scale_composition = comp("Preview"); | |
var scale_layer = scale_composition.layer("Controller - All Objects"); | |
var scale_effect = scale_layer.effect("Scale"); | |
var scale_slider = scale_effect("Slider"); | |
scale_slider = scale_slider / 100; | |
var horizontal_flip_composition = comp("Preview"); | |
var horizontal_flip_layer = horizontal_flip_composition.layer("Controller - All Objects"); | |
var horizontal_flip_effect = horizontal_flip_layer.effect("Horizontal Flip"); | |
var horizontal_flip_checkbox = horizontal_flip_effect("Checkbox"); | |
horizontal_flip_checkbox = horizontal_flip_checkbox == 1 ? -1 : 1; | |
var logo_composition = comp("Preview"); | |
var logo_layer = logo_composition.layer("Controller - All Objects"); | |
var logo_effect = logo_layer.effect("Logo"); | |
var logo_checkbox = logo_effect("Checkbox"); | |
var title_composition = comp("Preview"); | |
var title_layer = title_composition.layer("Controller - All Objects"); | |
var title_effect = title_layer.effect("Title"); | |
var title_checkbox = title_effect("Checkbox"); | |
var subtitle_composition = comp("Preview"); | |
var subtitle_layer = subtitle_composition.layer("Controller - All Objects"); | |
var subtitle_effect = subtitle_layer.effect("Subtitle"); | |
var subtitle_checkbox = subtitle_effect("Checkbox"); | |
var object_composition = comp("Center"); | |
var object_layer = object_composition.layer("Center Object"); | |
var object_rectangle = object_layer.sourceRectAtTime(); | |
var object_width = logo_checkbox == 1 ? object_rectangle.width : 0; | |
var object_height = logo_checkbox == 1 ? object_rectangle.height : 0; | |
var text_1_composition = comp("Center"); | |
var text_1_layer = text_1_composition.layer("Title"); | |
var text_1_properties = text_1_layer.text; | |
var text_1_source = text_1_properties.sourceText; | |
var text_1_style = text_1_source.style; | |
var text_1_size = text_1_style.fontSize; | |
var text_1_leading = text_1_style.autoLeading ? (text_1_size * 1.2) : text_1_style.leading; | |
var text_1_rectangle = text_1_layer.sourceRectAtTime(); | |
var text_1_width = title_checkbox == 1 ? text_1_rectangle.width : 0; | |
var text_1_height = title_checkbox == 1 ? text_1_rectangle.height : 0; | |
var text_1_hidden = text_1_rectangle.height; | |
var text_1_lines = title_checkbox == 1 ? Math.ceil(text_1_height / text_1_leading) : 0; | |
var text_1_lines_height = text_1_lines > 0 && title_checkbox == 1 ? text_1_size * text_1_lines : 0; | |
var text_1_x_height = text_1_lines > 0 && title_checkbox == 1 ? text_1_height / text_1_lines : 0; | |
var text_2_composition = comp("Center"); | |
var text_2_layer = text_2_composition.layer("Subtitle"); | |
var text_2_properties = text_2_layer.text; | |
var text_2_source = text_2_properties.sourceText; | |
var text_2_style = text_2_source.style; | |
var text_2_size = text_2_style.fontSize; | |
var text_2_leading = text_2_style.autoLeading ? (text_2_size * 1.2) : text_2_style.leading; | |
var text_2_rectangle = text_2_layer.sourceRectAtTime(); | |
var text_2_width = subtitle_checkbox == 1 ? text_2_rectangle.width : 0; | |
var text_2_height = subtitle_checkbox == 1 ? text_2_rectangle.height : 0; | |
var text_2_hidden = text_2_rectangle.height; | |
var text_2_lines = subtitle_checkbox == 1 ? Math.ceil(text_2_height / text_2_leading) : 0; | |
var text_2_lines_height = text_2_lines > 0 && subtitle_checkbox == 1 ? text_2_size * text_2_lines : 0; | |
var text_2_x_height = text_2_lines > 0 && subtitle_checkbox == 1 ? text_2_height / text_2_lines : 0; | |
var center_composition = comp("Center"); | |
var center_composition_width = center_composition.width; | |
var center_composition_height = center_composition.height; | |
var center_composition_x_value = center_composition_width / 2; | |
var center_composition_y_value = center_composition_height / 2; | |
var center_height = text_1_height + text_2_height; | |
center_height = title_checkbox == 1 && subtitle_checkbox == 1 ? center_height + (text_2_size / 2) : center_height; | |
var center_hidden = text_1_hidden + text_2_hidden + (text_2_size / 2); | |
center_hidden = object_height > center_hidden ? center_hidden / object_height : object_height / center_hidden; | |
var center_scale = object_height > center_height ? center_height / object_height : object_height / center_height; | |
center_scale = title_checkbox == 1 || subtitle_checkbox == 1 ? center_scale : center_hidden; | |
center_scale = scale_slider == 1.0 ? center_scale : center_scale * scale_slider; | |
var center_width = text_1_width > text_2_width ? text_1_width + (object_width * center_scale) : text_2_width + (object_width * center_scale); | |
center_width = logo_checkbox == 1 && title_checkbox == 1 || logo_checkbox == 1 && subtitle_checkbox == 1 ? center_width + (text_2_size / 2) : center_width; | |
var logo_x_value = center_composition_x_value - (center_width / 2) + (object_width * center_scale / 2); | |
logo_x_value = logo_x_value + extra_horizontal_margin_slider; | |
var logo_y_value = center_composition_y_value; | |
logo_y_value = logo_y_value + extra_vertical_margin_slider; | |
var logo_horizontal_scale = logo_checkbox == 1 ? (center_scale * 100) * horizontal_flip_checkbox : 0; | |
var logo_vertical_scale = logo_checkbox == 1 ? center_scale * 100 : 0; | |
var title_x_value = center_composition_x_value - (center_width / 2) + (object_width * center_scale) + (text_2_size / 2 * logo_checkbox); | |
title_x_value = title_x_value + extra_horizontal_margin_slider; | |
var title_y_value = center_composition_y_value - (center_height / 2) + text_1_height; | |
title_y_value = title_y_value + extra_vertical_margin_slider; | |
var title_horizontal_scale = title_checkbox == 1 ? 100 : 0; | |
var title_vertical_scale = title_checkbox == 1 ? 100 : 0; | |
var subtitle_x_value = center_composition_x_value - (center_width / 2) + (object_width * center_scale) + (text_2_size / 2 * logo_checkbox); | |
subtitle_x_value = subtitle_x_value + extra_horizontal_margin_slider; | |
var subtitle_y_value = center_composition_y_value + (center_height / 2) - text_2_height; | |
subtitle_y_value = subtitle_y_value + extra_vertical_margin_slider; | |
var subtitle_horizontal_scale = subtitle_checkbox == 1 ? 100 : 0; | |
var subtitle_vertical_scale = subtitle_checkbox == 1 ? 100 : 0; | |
[logo_x_value, logo_y_value]; | |
[logo_horizontal_scale, logo_vertical_scale]; | |
[title_x_value, title_y_value]; | |
[title_horizontal_scale, title_vertical_scale]; | |
[subtitle_x_value, subtitle_y_value]; | |
[subtitle_horizontal_scale, subtitle_vertical_scale]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment