From: Andrey Kutejko Date: Sat, 14 Sep 2013 09:45:54 +0000 (+0300) Subject: make replaceColor alpha aware X-Git-Tag: 0.5~41 X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;h=06c14c0c701780ea4087f56a6e77a18aef805715;p=ipf.git make replaceColor alpha aware --- diff --git a/ipf/image.php b/ipf/image.php index 3c7164e..56f9b1e 100644 --- a/ipf/image.php +++ b/ipf/image.php @@ -234,15 +234,24 @@ class IPF_Image 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); + } } } }