In this normal case, when we need to composite a image on another image, we use :
exec("convert 1.jpg 2.jpg -geometry +0+0 -compose DstOver -composite result.jpg);
and 0,0 points are the start line in left site of picture. I need to use my points from right side for example i have a jpg file with 500px height and 500px width and i need to composite image2 from 500,0 . its not good because if your image2 file has 100px in 100px height and width, your result hasn't any change in view.
my goal is compose from right side of image because my image2 has different width and height every time.
i mean i need compose from 3 and 4 point like picture. I try Imagemagick place image in bottom right corner but this solution compose with SouthEast , SouthWest and ... I need use my geometry size and points..
With image with fixed size i do not have any problem but i create text with imagemagick and it may with 1 charachter or more and in in this case my width of png text has different size.
Edit : In fact i get text from input and with different length then compose with background picture like:
ok, i need compose with right corner of "Sample Text 2" like picture, not left like "Text1" when i create text png file it may be created by different width and height . (sorry i can't explain better and sorry for my bad english)
Edited
Ok, I am getting closer to understanding what you want, First observation is that if you specify -gravity
then the offset in the geometry
is relative to the gravity - it moves the overlaid image INWARDS from the gravity corner by the amount you specify in the geometry offset. So let's start by setting the gravity to NorthEast to put the overlay in the top-right corner:
convert background.jpg overlay.jpg -gravity northeast -composite out.jpg
Now let's get the width of the overlay and use it to calculate the geometry you require, assuming you want the overlaid image to have its right edge 50 pixels in from the background's right edge:
geom=$(convert overlay.jpg -print "+%[fx:w+50]+0" null:)
echo $geom # this is just to show what is happening - you don't need it
+150+0
convert background.jpg overlay.jpg -gravity northeast -geometry $geom -composite out.jpg
Of course you can do that in a single command like this:
convert background.jpg overlay.jpg -gravity northeast -geometry $(convert overlay.jpg -print "+%[fx:w+50]+0" null:) -composite out.jpg
Original Answer
I am sorry, but I still don't understand exactly what you are asking, so I will answer what I think you mean and maybe you can explain what is wrong with my understanding.
convert -size 500x500! xc:red background.jpg # make a big red background
convert -size 100x100! xc:blue overlay.jpg # make a smaller blue overlay
# place overlay on image at desired position
convert background.jpg overlay.jpg -geometry +360+40 -composite out.jpg