Activity › Forums › Adobe After Effects Expressions › ‘Infallible Scale Expression’ – Problems with auto scaling images to comp size
-
‘Infallible Scale Expression’ – Problems with auto scaling images to comp size
Malcolm Ricci replied 5 years, 10 months ago 4 Members · 14 Replies
-
Malcolm Ricci
July 6, 2020 at 2:57 pmHey guys,
So I’ve run into another problem with this expression.
The expression that I’m currently using was provided by Dan and it works great with jpegs, however when it comes to applying it to pngs, the expression calculates the boundary box of the png, rather than the content of the png itself.
Therefore although the expression does indeed scale the png to the required size, some pngs end up looking larger or smaller than others due to the difference in ‘space’ between the actual image and the boundary box of the image.
Is there a way to modify this expression so that it could calculate the ‘pixels’ or ‘content’ of the layer, rather than the boundary box?
I know of a script that can do this, it’s called ‘Auto Crop’ if I’m not mistaken, however I have to work with expressions and not scripts since the rendering is taking place on a server with just the AE render engine running.
I’ve uploaded three images for your reference.
Any help with this would be greatly appreciated.
Thanks,
Malcolmw = thisLayer.width;
h = thisLayer.height;
try{
p = thisLayer.source.pixelAspect;
}catch(e){
p = 1;
}
compW = thisComp.width;
compH = thisComp.height;
compP = thisComp.pixelAspect;
if ((w*p)/h > (compW*compP)/compH){
s = ((compW*compP)/(w*p))*100;
}else{
s = (compH/h)*100;
}
[s,s] -
Tomas Bumbulevičius
July 10, 2020 at 10:38 amHey Malcolm, it is expected that size will be gathered from actual width/height, and not boundaries-exclusive .pngs.
While I haven’t tried this, it might be possible to achieve it by pixels sampling. But expressions based solution of this kind would be computation heavy.
Idea would be scanning image from corners, until non-alpha sampling value is found. Anyone has a better idea for this?
Find out more:
Motion Graphics Design & After Effects Tutorials
On YT
On VH -
Filip Vandueren
July 10, 2020 at 10:46 amYes,
I think I’ve found a workaround for the slowness of finding an image’s “true sourceRect”
see this thread:
https://forums.creativecow.net/thread/227/42469
-
Malcolm Ricci
July 10, 2020 at 12:11 pmThanks for the replies Tomas and Filip.
Filip I’ve just realised that you responded on the other thread. Apologies for not getting back to you earlier.
It seems pretty complex but I’ll give it a whirl and follow it step by step and get back to you 🙂
Reply to this Discussion! Login or Sign Up