• Global community
• Language:
• Deutsch
• English
• EspaÃ±ol
• FranÃ§ais
• PortuguÃªs
• æ—¥æœ¬èªžã‚³ãƒŸãƒ¥ãƒ‹ãƒ†ã‚£
Dedicated community for Japanese speakers
• í•œêµ­ ì»¤ë®¤ë‹ˆí‹°
Dedicated community for Korean speakers
Exit
• set scale in pixels in After Effects using Express...

# set scale in pixels in After Effects using Expressions

Participant ,
Aug 22, 2017 Aug 22, 2017

Copied

Hey everyone!

I often set the scale in pixels, using right click on a scale, hitting Edit, and then enter scale in Pixels. How can set the scale using expressions? And generally, how do you set the units using expressions?

returning ["200px","200px"] results in error

Thanks for help!

TOPICS
Expressions

Views

17.4K

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Advocate , Aug 26, 2017 Aug 26, 2017

Another approach would be to use expression. Apply this expression to scale property and adjust targetSize parameter. It will set Scale to maintain your desired pixel size.

`var targetSize = [500, 500];var sr = thisLayer.sourceRectAtTime(time);[targetSize[0] / sr.width * 100, targetSize[1] / sr.height * 100];`

6 Replies 6
LEGEND ,
Aug 22, 2017 Aug 22, 2017

Copied

AE has no "units". All values are intrinsic to the property stream and use its value ranges. Scale will always be in percent. You have to employ your own math to calculate the percentages. Simple 6th grade school stuff. Most commonly people use the linear() interpolator to that effect:

 linear(targetPixels,minPixels,maxPixels,minPercent,maxPercent)

Simply fill in your numerical values, e.g. for a 1000 px solid:

 linear(200,0,1000,0,100)

and it will return 20% for the scale.

Mylenium

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 26, 2017 Aug 26, 2017

Copied

Another approach would be to use expression. Apply this expression to scale property and adjust targetSize parameter. It will set Scale to maintain your desired pixel size.

`var targetSize = [500, 500];var sr = thisLayer.sourceRectAtTime(time);[targetSize[0] / sr.width * 100, targetSize[1] / sr.height * 100];`

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Guide ,
Aug 27, 2017 Aug 27, 2017

Copied

Another tip that will help is that you can set up Expression control sliders to adjust the target size, width and height values, this will give you slider controls that are much easier to access than opening and editing fiddly expressions.

Just create the sliders, rename them Scale X (Pixels) and Scale Y (Pixels).

X =effect("Scale X (Pixels)")("Slider");

Y = effect("Scale Y (Pixels)")("Slider")

var targetSize = [X, Y];

var sr = thisLayer.sourceRectAtTime(time);

[targetSize[0] / sr.width * 100, targetSize[1] / sr.height * 100];

Hope this helps ðŸ™‚

Angie Taylor

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Aug 18, 2021 Aug 18, 2021

Copied

Thank you for this! It's been a life saver ðŸ™‚

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Nov 08, 2023 Nov 08, 2023

Copied

it would be great to make a similar option...
but just to use 1 slider... scale x in pixels, for example, and mantain proportional height??

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
New Here ,
Nov 08, 2023 Nov 08, 2023

Copied

LATEST

var sr = thisLayer.sourceRectAtTime(time);

[(VARIABLE SLIDER) / sr.width * 100, transform.scale[0];