Ну, вы можете сделать это с GD и парой циклов:
$img = imagecreatefromstring(file_get_contents($imgFile));
$width = imagesx($img);
$hieght = imagesy($img);
$black = imagecolorallocate($img, 0, 0, 0);
$white = imagecolorallocate($img, 255, 255, 255);
for ($x = 0; $x < $width; $x++) {
for ($y = 0; $y < $width; $y++) {
$color = imagecolorat($img, $x, $y);
$color = imagecolorforindex($color);
if ($color['alpha'] == 1) {
imagesetpixel($img, $x, $y, $black);
} else {
imagesetpixel($img, $x, $y, $white);
}
}
}
Или вы можете заменить цвета (это может или не может работать):
$img = imagecreatefromstring(file_get_contents($imgFile));
$maxcolors = imagecolorstotal($img);
for ($i = 1; $i <= $maxcolors; $i++) {
$color = imagecolorforindex($i);
if ($color['alpha'] == 1) {
imagecolorset($img, $i, 0, 0, 0);
} else {
imagecolorset($img, $i, 255, 255, 255);
}
}