Auto-Scale Image to Text | After Effects Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's up everyone welcome back to another mograph mindset tutorial i'm going to share a really useful expression that i used in this motor to auto scale an image to text to follow along you can download the motors in the description double-click the vertical one and it'll automatically launch ae extract the file and it'll open up the project from here you have full access to edit everything included in the mowgr this text layer right here in the bottom left has this tape background that auto scales to the text if i change this text out the tape will grow with it and we can even adjust the padding how is the setup the tape layer is this orange layer right here i'm going to solo that and the text layer so we can just focus on these two and i've got a few expressions on this layer the scale expression looks intimidating but we'll rebuild it from scratch and i'll explain every step of the way let me import my tape layer again and i'll turn off this old one and i want to auto scale it to this text layer right first of all let's get it in the right area and let's scale it down so that optically it fits our text and i'll delete the old one and then shy all of our layers except for the ones that we're working with so we have a clean timeline our scale is percentage based meaning we're not going to see the actual pixel dimensions that this is taking up in our composition so i've set some rulers to see the edges of our text what you could do is measure from one ruler to the next to figure out the distance and therefore the size of our text layer however a better way to measure things is actually just to right click go to transform scale and change units from percentage of source or composition to pixels and this will report the actual pixel dimensions of a layer's bounding box so the text layer is 234 by 26 pixels we can do the same for our scaled tape layer so transform scale and we can see that this is currently taking up 308 by 97 pixels and you can see our scale values here so with that info i'm going to start building this out so we're going to add an expression to our scale layer and we know we're going to need a few values the first thing we're going to need is our target layer this is the layer that we want to auto scale to so i'll make a variable for that and just pick whip our text layer now we need our target width which is just the target layer source rectit time dot width and that is going to give us that 234 pixel value we need our target height so same thing for the target height source rectangle time dot height and if we output target width and target height that's giving us 234 by 26 but now our tape layer is stretching 234 percent on the x and 26 on the y because the scale property is percentage based not pixel based we need to convert this tape layers size in pixels to our target text layer size in pixels so let's create some new variables for this width and we'll say this layer dot width and var this height and this layer dot height and what does that give us that gives us 710 and 319. hold up when we measured this layer before it showed us 308 by 97 well measuring this layer.width or this layer.height gives us the original dimensions of the layer before any transform effects like scale are applied 710 and 319 is the original pixel size of our tape layer png all right so i'm just going to add some comments here to remember our values so we had 710 319 and for our target width we had 234 and 26. i'm just adding comments to remember our pixel values now that we have the pixel dimensions of our text layer and our tape layer we really just have to do some basic math so let's say that x equals target width over this width and y equals target height over this height and output that what does that give us it looks like 0.3 on the x and 0.1 on the y let's do this math ourselves so our target width of 234 divided by this width of 710 gives us 0.3295 and our target height of 26 divided by 319 gives us 0.0815 if you multiply these by 100 then you would have 32.95 percent and 8.15 percent so i'll multiply these both by 100 and we're getting about those values 33 and 8.4 our tape layer is stretching 33 on the x and 8.4 percent on the y and now it looks like it's fitting to our text layer i'm going to add two sliders with value 100 and rename them to padding x and padding y pick whip to replace the hard-coded hundred value with our new sliders now we can increase the ratio here and we know that if we leave it at 100 then it'll fit perfectly versus we can say it's 50 or 200 percent so the problem is if you move your text layer your tape layer is not going to follow and likewise if you add lines then your tape layer is going to grow from the wrong place so our tape layer's anchor point is directly in the center so for our text layer we want to force that anchor point to be directly in the center of that layer also so let's open up its anchor point property and add a simple expression so left top width height equals this layer dot source reactive time and that will pull the left top width and height values from this layer and then to center it we just say left plus width over two and top plus height over two and that's how you can auto center an anchor point now when you change the text your anchor point will always stay centered in that text layer so to get the tape to follow it you can just parent it however same deal where it's not locking to that anchor point position so all we have to do is open up our position property pick whip the position to the anchor point and voila now you can move this around to your heart's content change out the text and use our padding x and y sliders and everything will auto scale and reposition automatically i'm going to close that up so to recap here's our key formula you just need to divide your target pixel size over your current pixel size and multiply it by 100 if you keep that principle in mind you'll be able to auto scale any layer to anything else you can auto scale graphic layers to text layers layers to the bounds of a composition layers to masks and shapes etc this is a really useful technique and i haven't seen it covered before hope you guys find this useful feel free to dig into the project i think it's a cool one and you'll probably learn something if you try to break it apart and rebuild things yourself hope you enjoyed catch you in the next one
Info
Channel: Mograph Mindset
Views: 179
Rating: undefined out of 5
Keywords:
Id: IPSUJKKgqCk
Channel Id: undefined
Length: 6min 1sec (361 seconds)
Published: Thu Apr 22 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.