Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Scaling layers with expressions

  • Scaling layers with expressions

    Posted by Razamataz on December 1, 2005 at 5:19 pm

    Hello what i’m tyring to do is scale my layers to match the height of my composit whilst at the same time keeping the aspect ratio. All the images are different sizes and there are 1000’s of them.
    Thanks

    Ben Insler replied 20 years, 5 months ago 3 Members · 3 Replies
  • 3 Replies
  • Mylenium

    December 1, 2005 at 6:17 pm

    Try this:

    my_scale=thisComp.height/height*100;

    [my_scale,my_scale]

    Mylenium

    [Pour Myl

  • Ben Insler

    December 1, 2005 at 7:02 pm

    Nice expression Mylenium, but here’s a little tweak because yours only works for images that are taller than they are wide (so images that are wider than they are tall will get cropped on the sides). I added a condition to check which is larger, the width or the height, and the expression scales to the larger of the two to fit the whole image. Also, if the scaling is occuring based on the width, it is automatically scaling based on the comp’s pixel aspect ratio. expression is below:

    if(height>width) x=thisComp.height/height*100; else x=thisComp.width/width*(thisComp.pixelAspect*100);
    [x,x]

    Hope that works.
    -Ben

  • Ben Insler

    December 1, 2005 at 9:37 pm

    sorry… I thought about the expression again and realized that undesired cropping still could occur… I changed the condition so that rather than choosing the scaling method based on the longer width or height of the image, it compares the image’s width/height ratio to that of your comp. If the ratio is wider than your comp, it scales it down based on the width; if it’s taller it scales it down by the height. The expression is below.

    if((width/height)<=((thisComp.width*thisComp.pixelAspect)/thisComp.height)) x=thisComp.height/height*100; else x=thisComp.width/width*(thisComp.pixelAspect*100); [x,x] -Ben

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy