1
votes

I'm trying to port a PHP script to Ruby and until now I only used ImageMagick to convert from one file-format to another. Meaning: Yes, I'm an ImageMagick newbie. ;-)

Somewhere inside the PHP script the following code is executed:

$output = array();
$returnValue = 0;
$cmd = 'convert '.$pngFile->path.' -resize 1x1 -alpha on -channel o -format "%[fx:u.a]" info:'
exec($cmd, $output, $returnValue);

Using the ImageMagick documentation for convert I identified the following options:

  • -resize 1x1 Resize to 1x1 pixels (right?)
  • -alpha on Activate alpha-channel
  • -channel o Apply options to the opacity image-channel

My questions:

  1. What does -format "%[fx:u.a]" exactly do? I know that u is a symbol for first image in sequence and a one for alpha. But I don't get what the whole expression really does.
  2. What does info: stand for?
  3. What does this convert-command exactly do?

Thank you very much for your kind help.

Please note: The accepted answer on the following question has a very good answer to this question:

Understanding ImageMagick's convert and translating to Ruby RMagick

1

1 Answers

4
votes

Seems like it is computing the average opacity. The info format is a dummy image format that will instruct convert to output image information to stdout (: means stdout) in the format %[fx:u.a]. Resizing to 1x1 is probably a way of averaging.