Gravity has limited positions What if I want another?

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
Tidus

Gravity has limited positions What if I want another?

Post 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 ?
Tidus

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

Post 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"
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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
Last edited by fmw42 on 2009-10-13T15:59:57-07:00, edited 1 time in total.
Tidus

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

Post 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 ?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

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

Post 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
Tidus

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

Post by Tidus »

thanks bonzo but that code is not resize the uploaded image O_o
btw your webpage is great source thanks ^^
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

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

Post 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");
Tidus

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

Post by Tidus »

thanks for all your replies ^_^
Tidus

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

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

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

Post 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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

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

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply