#native_company# #native_desc#
#native_cta#

HUE shift

By Osman Darcan
on January 18, 2004

Version: 1

Type: Sample Code (HOWTO)

Category: Graphics

License: GNU General Public License

Description: this is a little script for shifting HUE in an image (remember hue, saturation, brightness?) in other words it means shifting the colors of a picture, for example red becomes green, gren becomes blue, blue becomes red.
Do whatever you want with it, but remember who’s tha man…

<?
/* made by ozzythaman, Osman DARCAN in 2003
   this is a script for shifting HUE data in an image,

   no explanation will be provided, figure it out yourself.
   play with it see what it does, input file is b2.jpg by default.
   change it to suit your own needs.

   if you still need any explanation you dont deserve to use this.

   to try out: put <img src='thisfile.php'> in a html file and change b2.png to an
   other image file (if not png: change the function to imagecreatefromjpg or whatever)
   this php file will act as an image itself.
*/

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);
?>