]> git.andy128k.dev Git - ipf.git/commitdiff
make replaceColor alpha aware
authorAndrey Kutejko <andy128k@gmail.com>
Sat, 14 Sep 2013 09:45:54 +0000 (12:45 +0300)
committerAndrey Kutejko <andy128k@gmail.com>
Sat, 14 Sep 2013 09:45:54 +0000 (12:45 +0300)
ipf/image.php

index 3c7164e4011db032c3e67ad174485d8950726b8a..56f9b1e19e6ea5b1d8050438f31498fd529f2cf6 100644 (file)
@@ -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);
+                                 }
                        }
              }
     }