set gravity

Discuss the conjure program and the Magick Scripting Language (MSL) here. MSL is an XML-based wrapper to the ImageMagick image-processing functions.
Post Reply
docjones2
Posts: 11
Joined: 2011-07-27T15:42:04-07:00
Authentication code: 8675308

set gravity

Post by docjones2 »

Hello,

I have read in various places that the msl language hasn't implemented all the features of PerlMagick yet, because of lack of demand -- however that features would implemented upon request "usually within a day."

There is currently no way to set gravity (ie: <set gravity='Center'/> ), which I need the ability to do.

I am using imagemagick 6.7 latest stable build, compiling source and running on various linux computers. I scoped msl.c and indeed gravity is not implemented in <set>

Thank you!
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: set gravity

Post by magick »

We have a patch in ImageMagick 6.7.1-1 beta (available sometime tomorrow) to fix the problem you reported. Thanks.
docjones2
Posts: 11
Joined: 2011-07-27T15:42:04-07:00
Authentication code: 8675308

Re: set gravity

Post by docjones2 »

Thank you!

I imagine the code will be available at ftp://ftp.imagemagick.org/pub/ImageMagick/beta/ , no?

I'll give it a whirl and post back on the status.
docjones2
Posts: 11
Joined: 2011-07-27T15:42:04-07:00
Authentication code: 8675308

Re: set gravity

Post by docjones2 »

It seems as if gravity is recognized now as a <set> option, however I'm not sure if it works correctly.

Consider the following

Code: Select all

<set gravity='Center' />
<crop geometry='250x250+0+0'/>
This doesn't seem to do what is expected, which (if I understand correctly) should be the equivalent of

Code: Select all

convert filename -gravity Center -crop 250x250+0+0 outname
If this assumption reflects my misunderstanding, how can I achieve a crop with gravity?

I have seen other tags (like composite) which support a gravity attribute, but crop does not.
docjones2
Posts: 11
Joined: 2011-07-27T15:42:04-07:00
Authentication code: 8675308

Re: set gravity

Post by docjones2 »

I figured it out.

at msl.c line 2141 there is the function call

Code: Select all

flags=ParsePageGeometry(msl_info->image[n],value,
                        &geometry,&exception);
changing this to

Code: Select all

flags=ParseGravityGeometry(msl_info->image[n],value,
                        &geometry,&exception);
will give the behaviour I expected, and fixes my issue.

Of course, I am no imagemagick developer and I haven't even ever used PerlMagick, so I do not know whether or not I am breaking any rules or going against an earlier decision to implement <crop> in this way, but it does what I want.

Post back with any comments or insights or reprimands!

On a side note, convert -crop calls CropImageToTiles as opposed to CropImage, so my change does not exactly mimic the command line behaviour 1:1, but it comes close for my purposes. I'm not sure how msl would handle tiling behaviour anyway.

Cheers


EDIT: This fix will not work if attributes height, width, x, y are used instead of geometry. Trying to fix that now.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: set gravity

Post by anthony »

There are two composition methods used for placement of images.
gravity and a geometry offset (set using -gravity and -geometry)
virtual canvas offsets. (set using -page and -repage)

They are rarely used together.
See http://www.imagemagick.org/Usage/compose/#geometry

Be sure you are not changing something that should not be changed!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply