Auto Resize Textbox in After Effects

TR
admin
|

Have you ever found yourself spending countless hours creating text animations in After Effects, only to realize that you need to adjust the background for each text element manually? Many motion graphics artists and video editors face this challenge daily. But what if I told you there’s a way to automate this process, saving you time and effort?

Setting Up Your Composition

To begin, let’s create a new composition in After Effects:

  1. Open After Effects and create a new composition
  2. Right-click and select “New Composition”
  3. Set the dimensions to 1920×1080 (standard HD resolution)
  4. Adjust the duration to 10 seconds (or as needed for your project)
  5. Click “OK” to create the composition

Creating Your Text Element

Now that we have our composition, let’s add some text:

  1. Select the Text tool from the toolbar
  2. Click in the center of the composition to create a text layer
  3. Type your desired text (e.g., “Adobe”)
  4. Choose a font (we’re using Gotham Black in this example)
  5. Adjust the text size and color as needed
  6. Use the Align panel to center the text both horizontally and vertically

Anchor Point Adjustment

An often overlooked but crucial step is adjusting the anchor point of your text:

  1. Select the Pan Behind tool (Y)
  2. Click and drag the anchor point to the center of your text
  3. Hold Ctrl (Windows) or Cmd (Mac) while dragging to snap to the exact center

Creating The Background Shape

Now, let’s add a background shape for our text:

  1. Select the Rectangle tool
  2. Ensure no layers are selected to avoid creating a mask
  3. Draw a rectangle around your text
  4. Adjust the fill color as desired (we’re using red in this example)
  5. Use the Selection tool to move the shape layer below the text layer

Automating Background Resizing

Here’s where the magic happens. We’ll use an expression to automatically resize the background shape based on the text:

  1. Expand the shape layer properties
  2. Open the Rectangle Path 1 properties
  3. Hold Alt (Windows) or Option (Mac) and click the stopwatch icon next to Size
  4. In the expression field, enter the following code:
s = thisComp.layer("Your Text Layer Name");
w = s.sourceRectAtTime().width;
h = s.sourceRectAtTime().height;
[w,h]
  1. Replace “Your Text Layer Name” with the actual name of your text layer

This expression links the size of the background shape to the dimensions of your text layer. Now, whenever you change the text or its size, the background will automatically adjust!

Fine-tuning The Background

To perfect the look of your background:

  1. Adjust the Position property of the shape layer if needed
  2. Add padding around the text by using the Offset Paths effect
  3. Experiment with different corner radii using the Rectangle Path properties
Ae Adobe Textbox

Adding Animation

Now that we have our text and background integrated, let’s add some animation:

  1. Select the shape layer
  2. Create a mask using the Rectangle tool (ensure “Tool Creates Mask” is enabled)
  3. Animate the Mask Path property to create a reveal effect
  4. Duplicate the shape layer and place it above the text layer
  5. Set the text layer’s Track Matte to use the duplicated shape layer

Creating Multiple Text Elements

To use this technique for multiple lines of text:

  1. Select all three layers (text, background, and mask)
  2. Press Ctrl+Shift+C (Windows) or Cmd+Shift+C (Mac) to pre-compose
  3. Duplicate the pre-composition for each line of text
  4. Edit the text within each pre-composition as needed
  5. Arrange the pre-compositions in your main composition

Conclusion

By utilizing this technique, you can significantly streamline your workflow in After Effects. The ability to automatically resize and animate backgrounds based on your text content not only saves time but also ensures consistency across your projects. As you become more comfortable with expressions in After Effects, you’ll find even more ways to automate and enhance your motion graphics work.