What is the use of 'FX' in imagemagick apart from effecting

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

What is the use of 'FX' in imagemagick apart from effecting

Post by agriz »

I was looking at fred's imagemagick scripts.

Code: Select all

convert xc: -format '%[fx:$ww/2]' info:
what does the "fx" do here?

instead of this,

half = $ww2 / 2;

does it have any other meaning here?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: What is the use of 'FX' in imagemagick apart from effect

Post by fmw42 »

convert xc: -format '%[fx:$ww/2]' info:
It is an IM calculator that computes to floating point precision. But I usually put that into a variable for later use.

w2=`convert xc: -format '%[fx:$ww/2]' info:`
or
w2=$(convert xc: -format '%[fx:$ww/2]' info:)
half = $ww2 / 2;
will be truncated to an integer. If you do not want to use IM, then you need to use the unix bc calculator, which is faster, but limited in what functions it can calculate. For example see
http://www.unix.com/man-page/OpenSolaris/1/bc/


see
http://www.imagemagick.org/Usage/transform/#fx_escapes
http://www.imagemagick.org/script/fx.php (any of these functions can be used in the calculator)

If you want to process a whole image by some function, then you have to use -fx "..." as in the link just above, unless there is an -evaluate function to do what you want.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: What is the use of 'FX' in imagemagick apart from effect

Post by anthony »

NOTE you do need to use double quotes " not single quotes ' when doing a shell variable substitution!


One reason to use convert %[fx:...] for floating point is that scripts already need to use "convert", so it is known to be available for floating point calculations. "bc" however may not be installed on cygwin (unix for dos) systems.

Also I would not go by a solaris manual for "bc", as olaris uses a VERY old version. Most systems (linux, mac, cgywin) use the GNU version of "bc" which is far more advanced with lot more functions and can create sub-functions as well.

The main problem with "bc" is that it is obtuse in it 'single letter' syntax requiring a well thumbed manual to use properly, much like IM, but less verbose.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: What is the use of 'FX' in imagemagick apart from effect

Post by fmw42 »

bc has on advantage. It is faster than using -fx in most cases. But bc has limited math functionality.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: What is the use of 'FX' in imagemagick apart from effect

Post by anthony »

I would not say it has limited functionality. Just very obtuse functionality.

Its big advantage over almost every other calculator program, including "convert" is that it can handle numbers of ANY size.

For example I have used it to deal with calculations involving prime numbers that are 20 base 10 digits long! that is not something that a 32 bit integer can handle (limited to 10 base 10 digits), though the new machines 64 bit integers now can handle it (20 base 10 digits), that wasn't the case 25 years ago when I was working with large prime numbers.

Remember that if you are dealing with very big numbers!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply