I'm failing at translating the following PHP/ImageMagick code into Ruby RMagick (to make it more manageable for future users and to understand what it's really doing):
$output = array();
$returnValue = 0;
$pngFiles = $myDir->find("/.png$/i");
foreach($pngFiles as $pngFile) {
$cmd = 'convert '.$pngFile->path.' -resize 1x1 -alpha on -channel o -format "%[fx:u.a]" info:'
exec($cmd, $output, $returnValue);
if($output[0] != 1) {
logMessage("PNG file contains some alpha transparency and will not be modified");
}
}
By now I thought I more or less understood what the convert-command is doing, but translating it to RMagick makes me rethink that.
For example: Why is $output[0] != 1
sometimes true
on PNGs in $myDir
, but RMagick's Image.alpha?
is always true
on PNGs in $myDir
? Am I missing something?
I think the best way to get me back on track would be, if anyone could explain to me what the convert-command is exactly doing (including the expression %[fx:u.a]
).
Update: In the meantime I've written the script I needed this information for. You can check it out at Github if it's to any help to you.