Resmin Değişik Renk Versiyonlarını Almak (Gri, Kırmızı, Yeşil, Mavi)

gif.php içeriği

<?php
class renk{
	var $resim;
	var $renk;
	function islem(){
		$toplam=imagecolorstotal($this->resim);
		for($i=0;$i<$toplam;$i++){
			 $eski=imagecolorsForIndex($this->resim,$i);
			 $ortak=(int)($eski['red']+$eski['green']+$eski['blue'])/3;
			 if(!$this->renk){
				 imagecolorSet($this->resim,$i,$ortak,$ortak,$ortak);
			 }elseif($this->renk==1){
				 imagecolorSet($this->resim,$i,$ortak,0,0);
			 }elseif($this->renk==2){
				 imagecolorSet($this->resim,$i,0,$ortak,0);
			 }elseif($this->renk==3){
				 imagecolorSet($this->resim,$i,0,0,$ortak);
			 }
		}
	}
	function degistir($resim,$renk){
		$resim=imagecreatefromgif($resim);
		$this->resim=$resim;
		$this->renk=$renk;
		$this->islem();
		header("Content-Type: image/gif");
		return imageGif($resim);
	}
}
$renk=new renk();
echo $renk->degistir($_GET["resim"],$_GET["renk"]);
?>

index.html içeriği

<img border=0 src="gif.php?resim=http://ulusanyazilim.com/wp-content/uploads/2018/05/dunya-300x300.gif&renk=0">
<img border=0 src="gif.php?resim=http://ulusanyazilim.com/wp-content/uploads/2018/05/dunya-300x300.gif&renk=1">
<img border=0 src="gif.php?resim=http://ulusanyazilim.com/wp-content/uploads/2018/05/dunya-300x300.gif&renk=2">
<img border=0 src="gif.php?resim=http://ulusanyazilim.com/wp-content/uploads/2018/05/dunya-300x300.gif&renk=3">

Çıktısı