最佳答案
您可以使用 ImageMagick 中的阈值函数将所有颜色变为黑色,如下所示:
<?php
// Load the PNG image
$im = new Imagick("image.png");
// Make everything black
$im->thresholdimage(65536);
$im->writeImage("result.png");
?>
如果您使用超过 16 位的每 channel 量化,那么这样做可能更合适:
#!/usr/local/bin/php -f
<?php
// Load the PNG image
$im = new Imagick("image.png");
// Work out quantum range - probably 255 or 65535
$m=$im->getQuantumRange();
$m=$m["quantumRangeLong"];
// Make everything darker than that black
$im->thresholdimage($m);
$im->writeImage("result.png");
?>
关于php - 用颜色覆盖 png 图像 (php),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33517308/