Page 1 of 1

Gravity has limited positions What if I want another?

Posted: 2009-10-13T12:18:15-07:00
by Tidus
in imagick command line when i merging two images into one image i want to merge the smaller one into middle of north and center area but gravity command has only specific positions. Is there any alternative to that ? like giving offsets or something else ?

Re: Gravity has limited positions What if I want another?

Posted: 2009-10-13T12:54:50-07:00
by fmw42

Re: Gravity has limited positions What if I want another?

Posted: 2009-10-13T13:14:44-07:00
by Tidus
Would you please provide an example code ? resize the image and and put the image between north and center then merge with the base image. I am using for only resize the uploaded image its like "-gravity center -geometry 90"

Re: Gravity has limited positions What if I want another?

Posted: 2009-10-13T13:24:32-07:00
by fmw42
You can mix -gravity and -geometry. But you still need to compute the offset you want to use relative to the gravity.

-geometry offsets are relative to the upper left corner of the background image.

Try this:

convert logo: rose: -geometry +100+0 -compose atop -composite logo_rose.gif

-geometry can also resize the last source image. So see this also

convert logo: rose: -geometry 100x100+100+0 -compose atop -composite logo_rose2.gif

or the equivalent using -resize

convert logo: \( rose: -resize 100x100 \) -geometry +100+0 -compose atop -composite logo_rose3.gif

Re: Gravity has limited positions What if I want another?

Posted: 2009-10-13T13:33:29-07:00
by Tidus
system("composite -geometry 95+0+80 $uploadedimg -geometry 100% $baseimage $compositedimage");

thats what I use. but it still freezes the left corner O_o


by the way what is compose atop stands for ?

Re: Gravity has limited positions What if I want another?

Posted: 2009-10-13T13:54:01-07:00
by Bonzo
Try:

Code: Select all

system("composite -gravity center -geometry +95+80 $uploadedimg $baseimage $compositedimage");
Check out my site for some php examples :D

I am working on a list of examples showing how all the different operators work and are used which I should be ready to upload soon.

A rough page 1 - http://www.rubble.info/TESTS/examples/part1.php

Re: Gravity has limited positions What if I want another?

Posted: 2009-10-13T14:02:27-07:00
by Tidus
thanks bonzo but that code is not resize the uploaded image O_o
btw your webpage is great source thanks ^^

Re: Gravity has limited positions What if I want another?

Posted: 2009-10-13T14:12:26-07:00
by Bonzo
Sorry didnt see the resize part; -geometry is depreciated for resizing and you use either -resize or -thumbnail.

Try:

Code: Select all

system("convert $uploadedimg -resize 100x100 $baseimage -gravity center -composite $compositedimage");
or:

Code: Select all

system("convert ( $uploadedimg -resize 100x100 ) $baseimage -gravity center -composite $compositedimage");

Re: Gravity has limited positions What if I want another?

Posted: 2009-10-13T14:28:22-07:00
by Tidus
thanks for all your replies ^_^

Re: Gravity has limited positions What if I want another?

Posted: 2009-10-13T14:37:27-07:00
by Tidus
this code actually works

Code: Select all

   system("composite -gravity north -geometry 90x90+0+50 $newname $fullcopy $compositeimage");
I dont know why dont know how :D

the result is : http://img97.imageshack.us/img97/9713/93095527.jpg

Re: Gravity has limited positions What if I want another?

Posted: 2009-10-13T16:03:31-07:00
by fmw42
Tidus wrote:system("composite -geometry 95+0+80 $uploadedimg -geometry 100% $baseimage $compositedimage");

thats what I use. but it still freezes the left corner O_o


by the way what is compose atop stands for ?
-geometry 95+0+80 may not be valid. it needs to be in the form of -geometry WxH+X+Y or -geometry +X+Y

also -geometry 100% may not be valid and seems meaningless to me

for compose methods see http://www.imagemagick.org/Usage/compose/

atop means to put the one image on top of the other

Re: Gravity has limited positions What if I want another?

Posted: 2009-10-13T20:43:44-07:00
by anthony
not quite.

atop means put the image atop of the area covered by the destination image.

that is if the destination has transparency, it will NOT add to that images transparency. that is it will color the destination with the source image but
not change that images transparency.

If their is no transparency in the destination (it is fully opaque) then atop, is the same as ' over' .

Over is the normal composition method

Re: Gravity has limited positions What if I want another?

Posted: 2009-10-13T20:57:00-07:00
by anthony
Getting back to the original problem.

Gravity specifies a default position to place one image within another image.

Geometry then adjusts that position with the values pushing the placement away from the edge, if no edge is involved with a specific value it is a relative movement down and right.

As such -gravity south -geometry +10+20 will initiall place the image in the center against the bottom edge. The +20 (y offset) will then push that image placement 20 pixel inward and away from that edge, in other word upward. The +10
will as no edge is involve move the image right 10 pixels.

That is what they mean and that is how they work.

And yes their is no 'centered-north' type gravity position that is midway between
the center of and the top edge. In fact this is the first time I have even heard or thought about such as request. As such DIY by combining -gravity with -geometry is the best solution.


Note that gravity is also used for 'justification' purposes in various operations. That is for the relative position of images or components that are positioned side by side relative to each other. For example in multiple lines of text, or when appending images.

On occasion these two aspects clash, such as when 'annotating', but this is a fairly rare event, though very annoying when it does happen!

For example you can not currently specify a 'centered' gravity with a 'bottom aligned' justification so that the bottom edge of the image is placed in the 'center' of the destination image. that is because you get 'centered' justification comming from the 'centered' gravity. This 'separation' is something that has been requested many many times.