Activity › Forums › Adobe After Effects Expressions › How to align images side by side?
-
How to align images side by side?
Posted by Dotan Stern on March 25, 2009 at 5:09 pmI have few videos that i scaled i need to position them next to eeach other perfectly i can do it by nudging with the arrows but is there a better and quicker way to do it with expression or script?
maybe using the width? but is said i need it to work even if it is scaled and even rotateKevin Camp replied 17 years, 1 month ago 3 Members · 8 Replies -
8 Replies
-
Espen Jakobsen
March 25, 2009 at 7:28 pmHi there! You could apply an expression like this to the position property of your layers:
x = thisComp.layer(thisLayer, +1).transform.position[0] + thisComp.layer(“controls”).effect(“Xoffset”)(“Slider”);
y = transform.position[1];
z = transform.position[2];[x, y, z]
in this expression the layers’ x pos is based on the above layers x position, while the y and z positions are untouched
you’ll need to make a null object named “controls” and then apply a slider control to it named “Xoffset”, and then keep a “boss” layer at the bottom of the stack. Now the distance between the layers in the x axis will be controled by the slider.
-
Dotan Stern
March 25, 2009 at 9:17 pmThanx for the expression but that’s not what i meant
using what you suggested i still need to adjust the two layers myself which is better then to adjust 10 layers
but i wonder if there is a way to do it automatically
is there an expression to know the layer width? -
Dotan Stern
March 25, 2009 at 10:28 pmI figured something simple that works on an image if i haven’t scaled it and its
thisComp.layer(index-1).transform.position+width
but how can i keep this working even when i scale the layer? -
Kevin Camp
March 26, 2009 at 6:02 pmyou’ll need to multiply by the layer’s scale to get the width of the layer after being scaled…
also, you need to use half the first layer’s width + half the current layer’s width to get accurate placement (if you had differing widths you original expression would not work quite right). and you’ll probably want to take the current layer’s scale in to account also….
so something like this should work for position:
L=thisComp.layer(index-1);
L.transform.position+[(L.width*L.transform.scale[0]/200)+(width*transform.scale[0]/200),0]taking rotation into account is a whole other ball of wax…
Kevin Camp
Senior Designer
KCPQ, KMYQ & KRCW -
Dotan Stern
March 26, 2009 at 9:56 pmThanx kevin its works
can you explain why you devide by 200 and them multiply again?
also i see on your expression and mine that if i use two squares it looks like they are snapped at the sides but i think one is overlapping the other they dont really snap at the sides
how is that? on both of the expression we use the other layer width
is there sometthing to do if the comp is square pixels or 1.07?
on one comp they look ok
on a different they ovelap
and on a third there is a little gap if you move them -
Kevin Camp
March 27, 2009 at 7:10 pm[Dotan Stern] “can you explain why you devide by 200 and them multiply again?”
i came to divide by 200 by simplifying the the equation some… since we needed half of the the above layer’s width times it’s scaled value (in decimal form), it looked like this:
( (L.width / 2) * (L.transform.scale[0] / 100) )
simplified down it became this:
(L.width*L.transform.scale[0]/200)
i then did the same thing for half the current layer’s width, to get the second part:
(width*transform.scale[0]/200)
[Dotan Stern] “also i see on your expression and mine that if i use two squares it looks like they are snapped at the sides but i think one is overlapping the other they dont really snap at the sides
how is that? on both of the expression we use the other layer width
is there sometthing to do if the comp is square pixels or 1.07?”i hadn’t tested that, but it does seem that the layer’s need to have the same pixel aspect ratio as the comp… so if you have a 1.07 par comp, then you’ll want to have 1.07 par layers… otherwise you’ll get a gap, or overlap…
we could modify the expression to correct for square pixel layers, in a non-square pixel comp with this expression:
L=thisComp.layer(index-1);
par = thisComp.pixelAspect;
L.transform.position+[(((L.width*L.transform.scale[0]/200)+(width*transform.scale[0]/200))/par),0]does something like that work better?
Kevin Camp
Senior Designer
KCPQ, KMYQ & KRCW -
Dotan Stern
March 28, 2009 at 1:09 pmThanx kevin it works great
except in a square pixel comp
also whay i meant that sometimes there is a gap is when you play a little with the size there is a little gap a pixel or less between them you can see it if you toggle the transpareny grid and then you see a small line
dont know why is that
thanx again for the help
Dotan -
Kevin Camp
March 29, 2009 at 6:44 pm[Dotan Stern] “Thanx kevin it works great
except in a square pixel comp”yeah, the expression would need to be modified if you had non-square pixel layers in a square pixel comp…. it currently doesn’t take into account the layer’s pixel aspect ratio and i’m not sure i can have the expression get that directly… so it might have to be entered manually.
[Dotan Stern] “when you play a little with the size there is a little gap a pixel or less between them you can see it if you toggle the transpareny grid and then you see a small line
dont know why is that “it is probably due to sub-pixel sampling… it’s a little like if you take two overlapping layers and set them both to 50% opacity, the result is 75% opaque (25% transparent), not 100% solid. so if you have two edges each place a a half pixel, the result would probably be 75% opaque for that edge.
Kevin Camp
Senior Designer
KCPQ, KMYQ & KRCW
Reply to this Discussion! Login or Sign Up