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);
}
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.');
$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);
+ }
+ }
+ }
}