我未能将以下 PHP/ImageMagick 代码翻译成 Ruby RMagick(以使其对未来的用户更易于管理并了解它的实际作用):
$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");
}
}
到目前为止,我认为我或多或少地理解了 convert-command 的作用,但是将其翻译为 RMagick 让我重新思考了这一点。
例如:为什么$output[0] != 1
有时 true
在$myDir
PNGs 上,但 RMagickImage.alpha?
总是在 true
PNGs上$myDir
?我错过了什么吗?
我认为让我回到正轨的最好方法是,如果有人可以向我解释 convert-command 到底在做什么(包括表达式%[fx:u.a]
)。
更新:与此同时,我已经编写了需要此信息的脚本。如果对您有任何帮助,您可以在 Github上查看。