Page 1 of 1
What is the use of 'FX' in imagemagick apart from effecting
Posted: 2013-08-29T21:58:15-07:00
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?
Re: What is the use of 'FX' in imagemagick apart from effect
Posted: 2013-08-29T22:22:51-07:00
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.
Re: What is the use of 'FX' in imagemagick apart from effect
Posted: 2013-09-29T23:54:57-07:00
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.
Re: What is the use of 'FX' in imagemagick apart from effect
Posted: 2013-09-30T10:06:40-07:00
by fmw42
bc has on advantage. It is faster than using -fx in most cases. But bc has limited math functionality.
Re: What is the use of 'FX' in imagemagick apart from effect
Posted: 2013-09-30T21:43:20-07:00
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!