0

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.

enter image description here

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..

enter image description here

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:

enter image description here

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)

Community
  • 1
  • 1
Nastary
  • 345
  • 4
  • 19
  • Can you post two input images and the composited result you seek please? – Mark Setchell Oct 07 '14 at 08:37
  • look at to my edit and URl in it please to find my mean – Nastary Oct 07 '14 at 08:48
  • I don't see any input or output images? – Mark Setchell Oct 07 '14 at 08:51
  • i mean url: http://stackoverflow.com/questions/11239948/imagemagick-place-image-in-bottom-right-corner and my edit. – Nastary Oct 07 '14 at 09:15
  • No, I still don't understand what you want to do. If your background image is 500x500 how can you expect to composite something on top at +500+0? It will be outside your background, so what will be "behind" it? – Mark Setchell Oct 07 '14 at 09:41
  • Please show your background image and the file you want to composite over it and how it will look when done correctly. At the moment you are showing the same image composited twice in two different places neither of which matches what you say you want to do, which is to composite outside your original background image. – Mark Setchell Oct 07 '14 at 09:43
  • Dear http://stackoverflow.com/users/2836621/mark-setchell i fine must use composite multiply -gravity and -geometry but with different size of image2, i can't. – Nastary Oct 07 '14 at 10:15

1 Answers1

1

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

enter image description here

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    

enter image description here

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432