return $result;
}
- public function replaceColor($from, $to)
+ public function replaceColor($from, $to, $colorOnly=true)
{
$from = $this->color($from);
$to = $this->color($to);
+ if ($colorOnly) {
+ $from = $from & 0xFFFFFF;
+ $to = $to & 0xFFFFFF;
+ }
for ($y = 0; $y < $this->height; ++$y) {
for ($x = 0; $x < $this->width; ++$x) {
$at = imagecolorat($this->image, $x, $y);
- if ($at == $from)
- imagesetpixel($this->image, $x, $y, $to);
+ if ($colorOnly) {
+ if (($at & 0xFFFFFF) === $from)
+ imagesetpixel($this->image, $x, $y, $to | ($at & 0x7F000000));
+ } else {
+ if ($at === $from)
+ imagesetpixel($this->image, $x, $y, $to);
+ }
}
}
}