Search code examples
imagemagickimagickimagemagick-convert

Need to understand piece of code in ImageMagick


I have the following piece of code from ImageMagick command line utility which I am trying to understand so that I can map it to Imagick php wrapper.

This is the command line code

convert $dir/tmpT.mpc -alpha off -colorspace gray -write $dir/tmpTG.mpc \
-crop ${wd}x${ht}+${minx}+${miny} +repage -format "%[fx:100*mean-50]" info:

First question is what the "info:" flag at the end does?

The second question is what the fx formula "%[fx:100*mean-50]" does?

The third question is, will the tmpTG.mpc stay intact when the -crop, +repage are applied to tmpT.mpc or not?

Please help me with this


Solution

  • First question is what the "info:" flag at the end does?

    The info: is a coder protocol, not a flag. The coder simply writes information to a buffer, in your case STDOUT. The information output was requested by the -format flag.

    The second question is what the fx formula "%[fx:100*mean-50]" does?

    Two parts here. First is the percent escape format, and it's requesting info: to output the evaluated output of an FX expression. Second, the FX expression 100*mean-50 is calculating the mean of all color values, and doing some basic arthritic. I assume it's attempting to identify how close to 50% light/darkness an image is.

    The third question is, will the tmpTG.mpc stay intact when the -crop, +repage are applied to tmpT.mpc or not?

    The -write $dir/tmpTG.mpc is writing a cache file to disk AFTER removing alpha & grayscale operations, but BEFORE the crop & repage operations occur. It will not be affected, or updated.