Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Question-making positon and scaling expression

  • Question-making positon and scaling expression

    Posted by Ross Turiano on April 23, 2012 at 3:49 am

    Hello, I am still very new to expressions. I am trying to make an expression for this scenario. I want to be able to insert any size picture, (however many pixels) and always have it conform to be the same size in my Comp, as well as the positioning to be the same. I was thinking for the position I can pick whip it to a picture that is the position I want, then just turn the opacity to 0 for the picture that I am parenting. This way it can stay in the same position as this image, but you just wont see this image that I”m not using. I thought this would be an easy solution, but I could be wrong.

    But for the scaling I’m not sure exactly how I would write it. Like for example if the image is 440×500 pixels, and I go into the project folder and replace the file with a 1500×1400 image then in the comp, I want to make it fit exactly the size of the original image automatically, without me changing anything.

    I realize too that the dimensions/ratio of the picture might be a problem as well, like for example if I have a picture that is formatted as 16:9 and I replace it with a 4:3 image, then have the scaling setup automatically to be a certain value, it will skew/distort the image.

    I hope I am explaining this right, if it’s unclear let me know.
    I appreciate anybody’s help. Thanks

    Ross Turiano replied 14 years ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    April 23, 2012 at 6:55 am

    If you put your image in a precomp that is exactly the size of the image, you have several options for a scale expression. This expression will cause the image (and any replacement) to exactly fill the precomp (but will distort the image if the replacement has a different aspect ratio):

    w = thisComp.width/width;
    h = thisComp.height/height;
    [value[0]*w,value[1]*h]

    This one eliminates the distortion, and makes the best fit without cropping the image, but it may leave gaps at the top and bottom, or on the sides:

    w = thisComp.width/width;
    h = thisComp.height/height;
    if (w < h) value*w else value*h

    This one eliminates the distortion and fills the precomp, but may crop the top and bottom or the sides:

    w = thisComp.width/width;
    h = thisComp.height/height;
    if (w > h) value*w else value*h

    All of these assume that all the images are square pixels. If not, the expressions get somewhat more complicated.

    Dan

  • Ross Turiano

    April 23, 2012 at 10:26 pm

    Thank You so much, I think I am going with the 2nd expression you gave me, because I don’t want to stretch the image if the aspect ratio is not the same. I’d rather have it be a smaller image than distort/stretch it.

    Thanks for the help!!

    -Ross

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