Mega Code Archive

 
Categories / Php / Graphics
 

HUE shift

<? function make_seed() { list($usec, $sec) = explode(' ', microtime()); return (float) $sec + ((float) $usec * 100000); } $ar=array(0,0,0,0); srand(make_seed()); $onetwoorthree=rand(0,2); $first=rand(0,100)/100; $second=1-$first; $ar[$onetwoorthree]=$first; $ar[$onetwoorthree+1]=$second; if ($onetwoorthree+1>2) $ar[0]=$second; //echo " ".$ar[0]." ".$ar[1]." ".$ar[2]; $im = imagecreatefrompng("b2.png") or die ("Cannot Initialize new GD image stream"); header ("Content-type: image/jpeg"); error_reporting(0); $height=imagesy($im); $width=imagesx($im); $im2=imagecreatetruecolor($width,$height); for ($x=0;$x<$width;$x++){ for ($y=0;$y<$height;$y++){ $rgb = ImageColorAt($im, $x, $y); $r = ($rgb >> 16) & 0xFF; $g = ($rgb >> 8) & 0xFF; $b = $rgb & 0xFF; $r2=$r; $g2=$g; $b2=$b; $r=$r2*$ar[0]+$g2*$ar[1]+$b2*$ar[2]; $g=$r2*$ar[2]+$g2*$ar[0]+$b2*$ar[1]; $b=$r2*$ar[1]+$g2*$ar[2]+$b2*$ar[0]; $color = imagecolorallocate($im2, $r, $g, $b); imagesetpixel($im2,$x,$y,$color); } } imagejpeg($im2,"",80); ?>