snibgo's ImageMagick pages

Windows FOR

The Windows "For" command is useful for extracting values from ImageMagick.

For example:

FOR /F "usebackq" %%L ^
IN (`%IMG7%magick %1 %2 %3 %4 %5 %6 %7 %8 %9 -format "M_R=%%[fx:mean.r]\nM_G=%%[fx:mean.g]\nM_B=%%[fx:mean.b]" info:`) ^
DO set %%L

For readability, I often write the above as:

for /F "usebackq" %%L in (`%IMG7%magick ^
  %1 %2 %3 %4 %5 %6 %7 %8 %9 ^
  -format "M_R=%%[fx:mean.r]\nM_G=%%[fx:mean.g]\nM_B=%%[fx:mean.b]" ^
  info:`) do set %%L

This executes magick once. magick reads the image given by %1..%9, and spits out three lines for each image that is in the list. The "for" command prepends "set" to each line, and executes it. The overall effect is to set three environment variables. If the command is pasted to a file named getFracs.bat, then:

call getFracs rose: -crop 10%x10%+0+0

results in:

set M_R=0.191261
set M_G=0.180728
set M_B=0.173669

The equivalent syntax for bash is:

declare $(magick \
  %1 %2 %3 %4 %5 %6 %7 %8 %9 ^
  -format "M_R=%%[fx:mean.r]\nM_G=%%[fx:mean.g]\nM_B=%%[fx:mean.b]" ^
  info:)

Page version v1.0 18-Apr-2014.

Page created 02-Sep-2022 03:24:26.

Copyright © 2022 Alan Gibson.