<?php

FUNCTION inverseHex( $color )
{
     $color       = TRIM($color);
     $prependHash = FALSE;
 
     IF(STRPOS($color,'#')!==FALSE) {
          $prependHash = TRUE;
          $color       = STR_REPLACE('#',NULL,$color);
     }
 
     SWITCH($len=STRLEN($color)) {
          CASE 3:
               $color=PREG_REPLACE("/(.)(.)(.)/","\\1\\1\\2\\2\\3\\3",$color);
          CASE 6:
               BREAK;
          DEFAULT:
               TRIGGER_ERROR("Invalid hex length ($len). Must be (3) or (6)", E_USER_ERROR);
     }
 
     IF(!PREG_MATCH('/[a-f0-9]{6}/i',$color)) {
          $color = HTMLENTITIES($color);
          TRIGGER_ERROR( "Invalid hex string #$color", E_USER_ERROR );
     }
 
     $r = DECHEX(255-HEXDEC(SUBSTR($color,0,2)));
     $r = (STRLEN($r)>1)?$r:'0'.$r;
     $g = DECHEX(255-HEXDEC(SUBSTR($color,2,2)));
     $g = (STRLEN($g)>1)?$g:'0'.$g;
     $b = DECHEX(255-HEXDEC(SUBSTR($color,4,2)));
     $b = (STRLEN($b)>1)?$b:'0'.$b;
 
     RETURN ($prependHash?'#':NULL).$r.$g.$b;
}


require_once('../../includes_3.0/class.upload.php');

$temp = time()+rand(1000,9999);

$handle = new upload('test.jpg');
if ($handle->uploaded) {
    $handle->file_new_name_body = $temp;
    $handle->image_convert = 'gif';
		$handle->image_negative = true;
	  header('Content-type: ' . $handle->file_src_mime);
	  $image = $handle->Process('temp/');
}

$handle = new upload('temp/' . $temp . '.gif');
if ($handle->uploaded) {
		$handle->image_tint_color = inverseHex('#' .$_GET['hex']);
		$handle->image_negative = true;
	  header('Content-type: ' . $handle->file_src_mime);
	  echo $handle->Process();
}

unlink('temp/' . $temp . '.gif');


?>