Make a rectangle self-resize to text size

Create a shape layer, from effects menu apply Slider with the following expression

  1. Apply the sliderto your shape element.
  2. Rename the slider to “Padding“.
  3. In Shaper object, go to Content > Rectangle 1 > Rectangle Path 1 > Size
    • Alt + Click on Size.
  4. Apply the below code.
  5. Remember to rename your text layer to “Caption“.
// Define Variable
var x;

// Add padding to the shape object, if it has content
if(thisComp.layer("Captions").text.sourceText.value < 1) {x=0} else {x=35};


// Resize the shape based on the content
title = thisComp.layer("Captions").sourceRectAtTime();padding = effect("Padding")("Slider");[title.width+x+ padding, title.height + padding + 35]

Source


Leave a Reply

Your email address will not be published. Required fields are marked *