From 665006af5fd6bed2fe41cfba64332f2aa1959cac Mon Sep 17 00:00:00 2001 From: Andrey Kutejko Date: Fri, 13 Sep 2013 16:13:05 +0300 Subject: [PATCH] image: replace color utility --- ipf/image.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/ipf/image.php b/ipf/image.php index 539ff81..3c7164e 100644 --- a/ipf/image.php +++ b/ipf/image.php @@ -21,6 +21,9 @@ class IPF_Image else throw new Exception('Unknown image format '.$path); + imagealphablending($image, false); + imagesavealpha($image, true); + return new IPF_Image($image, $imageInfo[0], $imageInfo[1], $type, $path); } @@ -75,9 +78,9 @@ class IPF_Image if ($type == IMAGETYPE_JPEG) imagejpeg($this->image, $filename); - else if ($type == IMAGETYPE_GIF) + elseif ($type == IMAGETYPE_GIF) imagegif($this->image, $filename); - else if ($type == IMAGETYPE_PNG) + elseif ($type == IMAGETYPE_PNG) imagepng($this->image, $filename); else throw new Exception('Unknown file type.'); @@ -230,5 +233,18 @@ class IPF_Image $result->copyScale($this, $x, $y, $w, $h); return $result; } + + public function replaceColor($from, $to) + { + $from = $this->color($from); + $to = $this->color($to); + 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); + } + } + } } -- 2.49.0