( ′∀`)σ≡σ☆))Д′)レ(゚∀゚;)ヘ=З=З=Зε≡(ノ´_ゝ`)ノ HEX
HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux mail.thebrand.ai 6.8.0-107-generic #107-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 13 19:51:50 UTC 2026 x86_64
User: www-data (33)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: /var/www/html/includes/processFunctions.php
<?php


function imagealphamask( &$background, $mask ) {
    // Get sizes and set up new picture
    $xSize = imagesx( $background );
    $ySize = imagesy( $background );
    $newPicture = imagecreatetruecolor( $xSize, $ySize );
    imagesavealpha( $newPicture, true );
    imagefill( $newPicture, 0, 0, imagecolorallocatealpha( $newPicture, 0, 0, 0, 127 ) );

    // Resize mask if necessary
    if( $xSize != imagesx( $mask ) || $ySize != imagesy( $mask ) ) {
        $tempPic = imagecreatetruecolor( $xSize, $ySize );
        imagecopyresampled( $tempPic, $mask, 0, 0, 0, 0, $xSize, $ySize, imagesx( $mask ), imagesy( $mask ) );
        imagedestroy( $mask );
        $mask = $tempPic;
    }

    // Perform pixel-based alpha map application
    for( $x = 0; $x < $xSize; $x++ ) {
        for( $y = 0; $y < $ySize; $y++ ) {
            $alpha = imagecolorsforindex( $mask, imagecolorat( $mask, $x, $y ) );
            $alpha = 127 - floor( $alpha[ 'red' ] / 2 );
            $color = imagecolorsforindex( $background, imagecolorat( $background, $x, $y ) );
            imagesetpixel( $newPicture, $x, $y, imagecolorallocatealpha( $newPicture, $color[ 'red' ], $color[ 'green' ], $color[ 'blue' ], $alpha ) );
        }
    }
 
    $background = $newPicture;
}
function themeDetailsX($type,$themeid)
{
	   
	  
  $sql = "select * from profilepicture where id='$themeid' order by id DESC LIMIT 0,1";



$rs_settings = mysqli_query($link,"$sql"); 
		 while ($row_settings = mysqli_fetch_array($rs_settings)) {
			  $result = strtolower($row_settings["$type"]);
			 }  
 
  
	return $result;
	  	

	  }
	 
    
function imagehue(&$background, $angle) {
    if($angle % 360 == 0) return;
    $width = 600;
    $height = 600;

    for($x = 0; $x < $width; $x++) {
        for($y = 0; $y < $height; $y++) {
            $rgb = imagecolorat($background, $x, $y);
            $r = ($rgb >> 16) & 0xFF;
            $g = ($rgb >> 8) & 0xFF;
            $b = $rgb & 0xFF;            
            $alpha = ($rgb & 0x7F000000) >> 24;
            list($h, $s, $l) = rgb2hsl($r, $g, $b);
            $h += $angle / 360;
            if($h > 1) $h--;
            list($r, $g, $b) = hsl2rgb($h, $s, $l);            
            imagesetpixel($background, $x, $y, imagecolorallocatealpha($background, $r, $g, $b, $alpha));
        }
    }
}






function rgb2hsl($r, $g, $b) {
   $var_R = ($r / 255);
   $var_G = ($g / 255);
   $var_B = ($b / 255);

   $var_Min = min($var_R, $var_G, $var_B);
   $var_Max = max($var_R, $var_G, $var_B);
   $del_Max = $var_Max - $var_Min;

   $v = $var_Max;

   if ($del_Max == 0) {
      $h = 0;
      $s = 0;
   } else {
      $s = $del_Max / $var_Max;

      $del_R = ( ( ( $var_Max - $var_R ) / 6 ) + ( $del_Max / 2 ) ) / $del_Max;
      $del_G = ( ( ( $var_Max - $var_G ) / 6 ) + ( $del_Max / 2 ) ) / $del_Max;
      $del_B = ( ( ( $var_Max - $var_B ) / 6 ) + ( $del_Max / 2 ) ) / $del_Max;

      if      ($var_R == $var_Max) $h = $del_B - $del_G;
      else if ($var_G == $var_Max) $h = ( 1 / 3 ) + $del_R - $del_B;
      else if ($var_B == $var_Max) $h = ( 2 / 3 ) + $del_G - $del_R;

      if ($h < 0) $h++;
      if ($h > 1) $h--;
   }

   return array($h, $s, $v);
}

function hsl2rgb($h, $s, $v) {
    if($s == 0) {
        $r = $g = $B = $v * 255;
    } else {
        $var_H = $h * 6;
        $var_i = floor( $var_H );
        $var_1 = $v * ( 1 - $s );
        $var_2 = $v * ( 1 - $s * ( $var_H - $var_i ) );
        $var_3 = $v * ( 1 - $s * (1 - ( $var_H - $var_i ) ) );

        if       ($var_i == 0) { $var_R = $v     ; $var_G = $var_3  ; $var_B = $var_1 ; }
        else if  ($var_i == 1) { $var_R = $var_2 ; $var_G = $v      ; $var_B = $var_1 ; }
        else if  ($var_i == 2) { $var_R = $var_1 ; $var_G = $v      ; $var_B = $var_3 ; }
        else if  ($var_i == 3) { $var_R = $var_1 ; $var_G = $var_2  ; $var_B = $v     ; }
        else if  ($var_i == 4) { $var_R = $var_3 ; $var_G = $var_1  ; $var_B = $v     ; }
        else                   { $var_R = $v     ; $var_G = $var_1  ; $var_B = $var_2 ; }

        $r = $var_R * 255;
        $g = $var_G * 255;
        $B = $var_B * 255;
    }    
    return array($r, $g, $B);
}

function removeslashes($string)
{
    $string=implode("",explode("\\",$string));
    return stripslashes(trim($string));
}

  
  function cleanText($text)
{
 $text = html_entity_decode($text,ENT_NOQUOTES, "ISO-8859-1"); 
 // http(s)://
$text = preg_replace('|https?://www\.[a-z\.0-9]+|i', '', $text);
$text = preg_replace('|http?://www\.[a-z\.0-9]+|i', '', $text);
// only www.
$text = preg_replace('|www\.[a-z\.0-9]+|i', '', $text);
 $text = trim(preg_replace('/\s\s+/', ' ', $text));
 $text = preg_replace("/&#?[a-z0-9]{2,8};/i","",$text); 
 $text = preg_replace('/\s+/', ' ', trim($text));
		  $text = iconv("UTF-8", "UTF-8//IGNORE", $text);
 
 
  $text = str_replace(': ', ' ', $text);
   
  
$text = preg_replace('/#\S+ */', '', $text);	
$text = preg_replace('/@\S+ */', '', $text);

$text = str_replace('RT', ' ', $text);
$text = str_replace('\'', '', $text);
 	 
	
 $text = preg_replace("/&#?[a-z0-9]{2,8};/i","",$text); 
   $text = trim($text); 
   
					  $text = str_replace("'", "`", $text);
					  $text = str_replace('"', "`", $text);
					  $text = str_replace('\\', "", $text);
					     
return $text;
 }
  function checkFont($type,$column,$catalogid,$themeid)
{ 

  $sql = "select * from myfonts where catalogid='$catalogid' and themeid='$themeid' and layertype='$type' order by layerid DESC LIMIT 0,1";



$rs_settings = mysqli_query($link,"$sql"); 
		 while ($row_settings = mysqli_fetch_array($rs_settings)) {
			  $theFont = strtolower($row_settings["font"]);
			 }  
 
 
	return $theFont;
	}
      
function multiRequestX($data, $options = array()) {
 
  // array of curl handles
  $curly = array();
  // data to be returned
  $result = array();
 
  // multi handle
  $mh = curl_multi_init();
 
  // loop through $data and create curl handles
  // then add them to the multi-handle
  foreach ($data as $id => $d) {
 
    $curly[$id] = curl_init();
 
    $url = (is_array($d) && !empty($d['url'])) ? $d['url'] : $d;
    curl_setopt($curly[$id], CURLOPT_URL,            $url);
    curl_setopt($curly[$id], CURLOPT_HEADER,         0);
    curl_setopt($curly[$id], CURLOPT_RETURNTRANSFER, 1);
 
    // post?
    if (is_array($d)) {
      if (!empty($d['post'])) {
        curl_setopt($curly[$id], CURLOPT_POST,       1);
        curl_setopt($curly[$id], CURLOPT_POSTFIELDS, $d['post']);
      }
    }
 
    // extra options?
    if (!empty($options)) {
      curl_setopt_array($curly[$id], $options);
    }
 
    curl_multi_add_handle($mh, $curly[$id]);
  }
 
  // execute the handles
  $running = null;
  do {
    curl_multi_exec($mh, $running);
  } while($running > 0);
 
 
  // get content and remove handles
  foreach($curly as $id => $c) {
    $result[$id] = curl_multi_getcontent($c);
    curl_multi_remove_handle($mh, $c);
  }
 
  // all done
  curl_multi_close($mh);
 
  return $result;
}
function findSharp($orig, $final) 
{
	$final	= $final * (750.0 / $orig);
	$a		= 52;
	$b		= -0.27810650887573124;
	$c		= .00047337278106508946;
	
	$result = $a + $b * $final + $c * $final * $final;
	
	return max(round($result), 0);
} // findSharp()
	
   
       function 


WriteCaption($background,$text_size,$text_color,$text_color,$text_line_height,$text_align,$angle,$underline,$font_Text,$backgroundWidth,$backgroundHeight,$layer_y,$text_pad,$backgroundColor,$layer_x,$text)
	
	{                 
     				 $lines=array();
						$backgroundColor='transparent';
						$elements = "v/uploads/text/name.png";
					 $saveImage  ="0";
					 
					 
					  if($angle == 0){}else{$text_line_height=-30; $layer_y=$layer_y+110; $layer_x=$layer_x-10;}
					 
					 
							 $lines=array();
							$wordSizeArray=array();
							$arrWords=explode(" ", $text);        
							foreach($arrWords as $word){
								$wordSize=imagettfbbox($text_size, $angle, $font_Text, $word. " ");
								$wordWidth=abs($wordSize[0])+abs($wordSize[2]);
								$wordSizeArray[]=array('word'=>$word, 'size'=>$wordWidth);
							}
							
							$line='';
							$lineWidth=0;
							foreach($wordSizeArray as $wordDetail){
								$word=$wordDetail['word'];
								$wordWidth=$wordDetail['size'];
								$lineWidth+=$wordWidth;
								if($lineWidth<$backgroundWidth-($text_pad*2)){
									$line.= ' ' . $word;
								}else{
									$line.= "\n" . $word;
									$lineWidth=$wordWidth;
								}
							}
							
							 
					
							 $lines = explode("\n",$line);       
							
							if($text_line_height == 0){
								if($underline){
									$text_line_height = $text_size + ($text_size*80/100);
								}else{
									$text_line_height = $text_size + ($text_size*60/100);
								}
							}
							
							$startYPosition = $text_size+1;
						 
							
							list($text_colorRed, $text_colorBlue, $text_colorGreen) = hex2rgb($text_color);
							if($backgroundHeight==0){
								$backgroundHeight = $text_line_height * count($lines) + ($text_pad*2);
							}
					 
							
						  
							$text_color = imagecolorallocate($background, $text_colorRed, $text_colorBlue, $text_colorGreen);
									
						   
					
									$lineNumber=1;
							foreach($lines as $line){   
								
								$line=trim($line);
								list($xBLeft, $yBLeft, $xBRight, $yBRight, $xTRight, $yTRight, $xTLeft, $yTLeft) = imagettfbbox($text_size, $angle, $font_Text, $line);
								$lineWidth = abs($xBLeft) + abs($xBRight);
								
								
								
								
								
										switch ($text_align) {
								case 'left':
									$startXPosition = abs($xBottomLeft) + $text_pad;
									break;
								case 'right':
									$startXPosition = $backgroundWidth - $lineWidth - 1 - $text_pad;
									break;
								case 'center':
									$startXPosition = ($backgroundWidth - $lineWidth) / 2;
									break;
								default:
									$startXPosition = abs($xBottomLeft);
									break;
							}
							
						
								if($lineNumber==1 && $text_pad>0){
									$startYPosition+=$text_pad;
								}
								
								imagettftext($background, $text_size, $angle, $startXPosition+$layer_x, $startYPosition+$layer_y, $text_color, $font_Text, $line);
								if(strlen($line)>0){
									 underline($startXPosition, $lineWidth);
								}
								$startYPosition+=$text_line_height;
								$lineNumber++;
							}				 
						 
return $background;
    }    
    
    function underline($startXPosition, $lineWidth){
        if ($underline) {
            $underlineY=$startYPosition+5;
            imagesetthickness($background, 2);
            imageline($background, $startXPosition, $underlineY, $startXPosition+$lineWidth, $underlineY, $font_color);
        }
    }

    function hex2rgb($hex) {
        $hex = str_replace("#", "", $hex);

        if (strlen($hex) == 3) {
            $r = hexdec(substr($hex, 0, 1) . substr($hex, 0, 1));
            $g = hexdec(substr($hex, 1, 1) . substr($hex, 1, 1));
            $b = hexdec(substr($hex, 2, 1) . substr($hex, 2, 1));
        } else {
            $r = hexdec(substr($hex, 0, 2));
            $g = hexdec(substr($hex, 2, 2));
            $b = hexdec(substr($hex, 4, 2));
        }
        $rgb = array($r, $g, $b);
        
        return $rgb;
    }
    
    function pr($str){
        echo "<pre>";
        print_r($str);
        echo "</pre>";
    }
 
function gd_apply_overlay_layers($background, $brand, $amount,$x,$y,$url)
{

 
		 $picture = explode('.',$brand);
         $ext = strtolower($picture[1]);
		 
	switch ($ext)
{
	case 'gif':
		// We will be converting GIFs to PNGs to avoid transparency issues when resizing GIFs
		// This is maybe not the ideal solution, but IE6 can suck it
		$creationFunction	= 'ImageCreateFromGif';
		$outputFunction		= 'ImagePng';
		$mime				= 'image/png'; // We need to convert GIFs to PNGs
		$doSharpen			= FALSE;
		$quality			= round(10 - ($quality / 10)); // We are converting the GIF to a PNG and PNG needs a compression level of 0 (no compression) through 9
	break;
	
	case 'png':
	
		$creationFunction	= 'ImageCreateFromPng';
		$outputFunction		= 'ImagePng';
		$doSharpen			= FALSE;
		$quality			= round(10 - ($quality / 10)); // PNG needs a compression level of 0 (no compression) through 9
	break;
	
	default:
		$creationFunction	= 'ImageCreateFromJpeg';
		$outputFunction	 	= 'ImageJpeg';
		$doSharpen			= FALSE;
	break;
}	 
 
 	$width =600;$height =600;
	$photoFrame2 = imagecreatetruecolor($width, $height);
	imagealphablending($photoFrame2, false);
	imagesavealpha($photoFrame2, true);
 	$trans_colour = imagecolorallocatealpha($photoFrame2,  0, 0, 0, 127);
	imagefilledrectangle($photoFrame2, 0, 0, $width, $height, $trans_colour);
	$brand = $url . $brand . '';
	$photo2 = $creationFunction($brand);
	imagecopyresampled($photoFrame2, $photo2, 0, 0, 0,0, $width, $height, $width, $height);
	$photoFrame = imagecreatetruecolor($width, $height);
	imagecopy($photoFrame, $background, 0, 0, 0, 0, $width, $height);
	imagecopy($photoFrame, $photoFrame2, 0, 0, 0, 0, $width, $height);
	imagecopymerge($background, $photoFrame, 0, 0, 0, 0, $width, $height, $amount); 
	imagedestroy($photoFrame); 

	
	return $background;
}



 function checkType($brand)
{
				 if (strpos($brand, 'route=theUpdate') !== false){$type = "theUpdate" ; }
				 if (strpos($brand, 'route=thePlain') !== false){$type = "thePlain" ; }

				if (strpos($brand, 'route=theUrl') !== false){$type = "theUrl" ; }

				if (strpos($brand, 'route=theName') !== false){$type = "theName" ; }

				if (strpos($brand, 'route=profile') !== false){$type = "theProfile" ; }

				if (strpos($brand, 'route=theUser') !== false){$type = "theUser" ; }

				if (strpos($brand, 'route=theGraphics') !== false){$type = "theGraphics" ; }
	if (strpos($brand, '/filters/mood/') !== false){$type = "theGraphics" ; }
				if (strpos($brand, 'route=profilePic') !== false){$type = "ProfilePic" ; }
				
				if (strpos($brand, 'v/uploads/gthumbs') !== false){$type = "Uploaded" ; }
	return $type;
	}
	
	
	
 
/** Apply a PNG overlay */
function gd_apply_effect($background, $brand, $amount)
{

if ($_GET['action']=="cards")
		
		 {
			 $width = 640;  $height = 430;	
				
					 
		 
		 }
		 else
		 
		 {
			   if (!empty($_GET['description']))
		
		 {
			 $width = 640;  $height = 400;	 
		 }
		 else
		 
		 {
			  $width = 600;  $height = 666;	
		 }
		 
		 }
	


	// Get the size and MIME type of the requested image
/*$size	= GetImageSize($docRoot . $image);
$mime	= $size['mime'];*/
 

 
	$photoFrame2 = imagecreatetruecolor($width, $height);
	
	imagealphablending($photoFrame2, false);
	imagesavealpha($photoFrame2, true);
 
	$trans_colour = imagecolorallocatealpha($photoFrame2,  0, 0, 0, 127);
	
	imagefilledrectangle($photoFrame2, 0, 0, $width, $height, $trans_colour);
	$mag = $brand;
	
 
		
 
 
		$brand = 'filters/effects/' . $brand . '.png';
		$photo2 = imagecreatefrompng($brand);
		 
	
	
	/*include("mags/switch.php"); */
	imagecopyresampled($photoFrame2, $photo2, 0, 0, 0,0, $width, $height, $width, $height);
	
	$photoFrame = imagecreatetruecolor($width, $height);
	imagecopy($photoFrame, $background, 0, 0, 0, 0, $width, $height);
	imagecopy($photoFrame, $photoFrame2, 0, 0, 0, 0, $width, $height);
	imagecopymerge($background, $photoFrame, 0, 0, 0, 0, $width, $height, $amount); 
	imagedestroy($photoFrame); 
	
	return $background;
}
/** Apply a PNG overlay */
/** Apply a PNG overlay */
function gd_apply_overlay($background, $brand, $amount)
{

if ($_GET['action']=="cards")
		
		 {
			 $width = 640;  $height = 430;	
				
					 
		 
		 }
		 else
		 
		 {
			   if (!empty($_GET['description']))
		
		 {
			 $width = 640;  $height = 400;	 
		 }
		 else
		 
		 {
			  $width = 600;  $height = 666;	
		 }
		 
		 }
	


	// Get the size and MIME type of the requested image
/*$size	= GetImageSize($docRoot . $image);
$mime	= $size['mime'];*/
 

 
	$photoFrame2 = imagecreatetruecolor($width, $height);
	
	imagealphablending($photoFrame2, false);
	imagesavealpha($photoFrame2, true);
 
	$trans_colour = imagecolorallocatealpha($photoFrame2,  0, 0, 0, 127);
	
	imagefilledrectangle($photoFrame2, 0, 0, $width, $height, $trans_colour);
	$mag = $brand;
	
 
		
 
 
		$brand = 'filters/mood/' . $brand . '.png';
		$photo2 = imagecreatefrompng($brand);
		 
	
	
	/*include("mags/switch.php"); */
	imagecopyresampled($photoFrame2, $photo2, 0, 0, 0,0, $width, $height, $width, $height);
	
	$photoFrame = imagecreatetruecolor($width, $height);
	imagecopy($photoFrame, $background, 0, 0, 0, 0, $width, $height);
	imagecopy($photoFrame, $photoFrame2, 0, 0, 0, 0, $width, $height);
	imagecopymerge($background, $photoFrame, 0, 0, 0, 0, $width, $height, $amount); 
	imagedestroy($photoFrame); 
	
	
	
	
	
	return $background;
}
/** Apply a PNG overlay */

  
 function gd_apply_url($background, $newUrl, $amount,$x,$y,$w,$h)
{
 
  
		$picture = basename($newUrl);
 		 $picture = explode('.',$picture);
         $ext = strtolower($picture[1]);
		  
	switch ($ext)
{
	case 'gif':
		// We will be converting GIFs to PNGs to avoid transparency issues when resizing GIFs
		// This is maybe not the ideal solution, but IE6 can suck it
		$creationFunction	= 'ImageCreateFromGif';
		$outputFunction		= 'ImagePng';
		$mime				= 'image/png'; // We need to convert GIFs to PNGs
		$doSharpen			= FALSE;
		$quality			= round(10 - ($quality / 10)); // We are converting the GIF to a PNG and PNG needs a compression level of 0 (no compression) through 9
	break;
	
	case 'png':
	
		$creationFunction	= 'ImageCreateFromPng';
		$outputFunction		= 'ImagePng';
		$doSharpen			= FALSE;
		$quality			= round(10 - ($quality / 10)); // PNG needs a compression level of 0 (no compression) through 9
	break;
	
	default:
		$creationFunction	= 'ImageCreateFromJpeg';
		$outputFunction	 	= 'ImageJpeg';
		$doSharpen			= FALSE;
	break;
}
$source_img = $creationFunction($newUrl); //Create a copy of our image for our thumbnails...
 
 $new_w = 600;
$new_h = 600;
	
$orig_w = imagesx($source_img);
$orig_h = imagesy($source_img);
	
$w_ratio = ($new_w / $orig_w);
$h_ratio = ($new_h / $orig_h);
	
 
  
  
if ($orig_w > $orig_h ) {//landscape
	$crop_w = round($orig_w * $h_ratio);
	$crop_h = $new_h;
	$src_x = ceil( ( $orig_w - $orig_h ) / 2 );
	$src_y = 0;
} elseif ($orig_w < $orig_h ) {//portrait
	$crop_h = round($orig_h * $w_ratio);
	$crop_w = $new_w;
	$src_x = 0;
	$src_y = ceil( ( $orig_h - $orig_w ) / 2 );
} else {//square
	$crop_w = $new_w;
	$crop_h = $new_h;
	$src_x = 0;
	$src_y = 0;	
}
$dest_img = imagecreatetruecolor($new_w,$new_h);
imagecopyresampled($background, $source_img, 0 , 0 , $src_x, $src_y, $crop_w, $crop_h, $orig_w, $orig_h);



	return $background;
}
 
 
 function gd_apply_newpic($background, $newPic, $amount,$x,$y,$w,$h)
{
 
/* 	 	if (!empty($_GET['newPic']))
				{
					$newPic = $_GET['newPic'];
					 
					$background = gd_apply_logo($background,$newPic, 100,$x,$y,$w,$h);
 				}
*/
$width = 600;  $height = 600;	

	// Get the size and MIME type of the requested image
/*$size	= GetImageSize($docRoot . $image);
$mime	= $size['mime'];*/
 if(!empty($_GET['width'])){
		$newWidth= $_GET['width']; 
	$width = $newWidth;  $height = $newWidth;	

	  }

 
	$photoFrame2 = imagecreatetruecolor($width, $height);
	
	imagealphablending($photoFrame2, false);
	imagesavealpha($photoFrame2, true);
 
	$trans_colour = imagecolorallocatealpha($photoFrame2,  0, 0, 0, 127);
	
	imagefilledrectangle($photoFrame2, 0, 0, $width, $height, $trans_colour);
	$mag = $newPic;
	
 
		$picture = basename($newPic);
 		 $picture = explode('.',$picture);
         $ext = strtolower($picture[1]);
		  
	switch ($ext)
{
	case 'gif':
		// We will be converting GIFs to PNGs to avoid transparency issues when resizing GIFs
		// This is maybe not the ideal solution, but IE6 can suck it
		$creationFunction	= 'ImageCreateFromGif';
		$outputFunction		= 'ImagePng';
		$mime				= 'image/png'; // We need to convert GIFs to PNGs
		$doSharpen			= FALSE;
		$quality			= round(10 - ($quality / 10)); // We are converting the GIF to a PNG and PNG needs a compression level of 0 (no compression) through 9
	break;
	
	case 'png':
	
		$creationFunction	= 'ImageCreateFromPng';
		$outputFunction		= 'ImagePng';
		$doSharpen			= FALSE;
		$quality			= round(10 - ($quality / 10)); // PNG needs a compression level of 0 (no compression) through 9
	break;
	
	default:
		$creationFunction	= 'ImageCreateFromJpeg';
		$outputFunction	 	= 'ImageJpeg';
		$doSharpen			= FALSE;
	break;
}

if (strpos($newPic, 'http') !== false || strpos($newPic, 'https') !== false) {
    
}
else
{
	$newPic = 'v/uploads/gthumbs/' . $newPic;
	}
 
 
		
		$photo2 = $creationFunction($newPic);
		 
	
	 
	/*include("mags/switch.php"); */
	/*if($w > 600){$w=600;}*/
	imagecopyresampled($photoFrame2, $photo2, $x, $y, 0,0, $w, $h, $width, $height);
	
	$photoFrame = imagecreatetruecolor($width, $height);
	imagecopy($photoFrame, $background, 0, 0, 0, 0, $width, $height);
	imagecopy($photoFrame, $photoFrame2, 0, 0, 0, 0, $width, $height);
	imagecopymerge($background, $photoFrame, 0, 0, 0, 0, $width, $height, $amount); 
	imagedestroy($photoFrame); 
	
	return $background;
}
 

function gd_apply_logo($background, $brand, $amount,$x,$y,$w,$h)
{
	

/* 	 	if (!empty($_GET['newPic']))
				{
					$newPic = $_GET['newPic'];
					 
					$background = gd_apply_logo($background,$newPic, 100,$x,$y,$w,$h);
 				}
*/
$width = 600;  $height = 600;	

if(!empty($_GET['width'])){
		$newWidth= $_GET['width']; 
	$brand_width = $newWidth;   
	$brand_height = $newWidth; 
	$width = $newWidth;   
	$height = $newWidth;
  }

	// Get the size and MIME type of the requested image
/*$size	= GetImageSize($docRoot . $image);
$mime	= $size['mime'];*/
 

 
	$photoFrame2 = imagecreatetruecolor($width, $height);
	
	imagealphablending($photoFrame2, false);
	imagesavealpha($photoFrame2, true);
 
	$trans_colour = imagecolorallocatealpha($photoFrame2,  0, 0, 0, 127);
	
	imagefilledrectangle($photoFrame2, 0, 0, $width, $height, $trans_colour);
	$mag = $brand;
	
 
		
 		 $picture = explode('.',$brand);
         $ext = strtolower($picture[1]);
		 
	switch ($ext)
{
	case 'gif':
		// We will be converting GIFs to PNGs to avoid transparency issues when resizing GIFs
		// This is maybe not the ideal solution, but IE6 can suck it
		$creationFunction	= 'ImageCreateFromGif';
		$outputFunction		= 'ImagePng';
		$mime				= 'image/png'; // We need to convert GIFs to PNGs
		$doSharpen			= FALSE;
		$quality			= round(10 - ($quality / 10)); // We are converting the GIF to a PNG and PNG needs a compression level of 0 (no compression) through 9
	break;
	
	case 'png':
	
		$creationFunction	= 'ImageCreateFromPng';
		$outputFunction		= 'ImagePng';
		$doSharpen			= FALSE;
		$quality			= round(10 - ($quality / 10)); // PNG needs a compression level of 0 (no compression) through 9
	break;
	
	default:
		$creationFunction	= 'ImageCreateFromJpeg';
		$outputFunction	 	= 'ImageJpeg';
		$doSharpen			= FALSE;
	break;
}
 
		$brand = 'v/uploads/gthumbs/' . $brand;
		$photo2 = $creationFunction($brand);
		 
	
	
	/*include("mags/switch.php"); */
	imagecopyresampled($photoFrame2, $photo2, $x, $y, 0,0, $w, $h, $width, $height);
	
	$photoFrame = imagecreatetruecolor($width, $height);
	imagecopy($photoFrame, $background, 0, 0, 0, 0, $width, $height);
	imagecopy($photoFrame, $photoFrame2, 0, 0, 0, 0, $width, $height);
	imagecopymerge($background, $photoFrame, 0, 0, 0, 0, $width, $height, $amount); 
	imagedestroy($photoFrame); 
	
	return $background;
}
/** Apply a PNG overlay */
 
function button($x,$y,$left, $top, $padding_x, $padding_y, $color, $opacity, $corner_radius, $text, $text_color,$background,$font,$fontsize,$fontadjust){
 
	list($lefted,, $righted) = imageftbbox($fontsize, 0, "$font", "$text");

   /*$width = ($righted - $lefted) + (2*$padding_x);*/
 $width = ($righted - $lefted) + (2*$padding_x);
 $width=$width-6;
  /* $width = $left + strlen($text)*9 + 2*$padding_x; */
	$height = $top +  $fontadjust + 2*$padding_y;
	if(substr($color, 0, 1) == "#"){
		$color = substr($color, 1);
	}
$width= $width+$padding_x;
	$r = substr($color,0,2);
	$g = substr($color,2,2);
	$b = substr($color,4,2);

	$r = hexdec($r);
	$g = hexdec($g);
	$b = hexdec($b);

	if(substr($text_color, 0, 1) == "#"){
		$text_color = substr($text_color, 1);
	}

	$text_r = substr($text_color,0,2);
	$text_g = substr($text_color,2,2);
	$text_b = substr($text_color,4,2);

	$text_r = hexdec($text_r);
	$text_g = hexdec($text_g);
	$text_b = hexdec($text_b);

	$opacity = (100 - $opacity)/100 * 127;

	$bg = imagecreatetruecolor($left + $width, $top + $height);
	imagesavealpha($bg, true);
	$trans_color = imagecolorallocatealpha($bg, 0, 0, 0, 127);
	imagefill($bg, 0, 0, $trans_color);

	$rectangle_color = imagecolorallocatealpha($bg, $r, $g, $b, $opacity);

	$points_array = array(
		$left, $top + $corner_radius, //starting from top left corner before radius
		$left + $corner_radius - cos(deg2rad(22.5))*$corner_radius, $top + $corner_radius - sin(deg2rad(22.5))*$corner_radius,
		$left + $corner_radius - cos(deg2rad(45))*$corner_radius, $top + $corner_radius - sin(deg2rad(45))*$corner_radius,
		$left + $corner_radius - cos(deg2rad(67.5))*$corner_radius, $top + $corner_radius - sin(deg2rad(67.5))*$corner_radius,
		$left + $corner_radius, $top,

		$left + $width - $corner_radius, $top,
		$left + $width - $corner_radius + cos(deg2rad(67.5))*$corner_radius, $top + $corner_radius - sin(deg2rad(67.5))*$corner_radius,
		$left + $width - $corner_radius + cos(deg2rad(45))*$corner_radius, $top + $corner_radius - sin(deg2rad(45))*$corner_radius,
		$left + $width - $corner_radius + cos(deg2rad(22.5))*$corner_radius, $top + $corner_radius - sin(deg2rad(22.5))*$corner_radius,
		$left + $width, $top + $corner_radius,

		$left + $width, $top + $height - $corner_radius,
		$left + $width - $corner_radius + cos(deg2rad(22.5))*$corner_radius, $top + $height - $corner_radius + sin(deg2rad(22.5))*$corner_radius,
		$left + $width - $corner_radius + cos(deg2rad(45))*$corner_radius, $top + $height - $corner_radius + sin(deg2rad(45))*$corner_radius,
		$left + $width - $corner_radius + cos(deg2rad(67.5))*$corner_radius, $top + $height - $corner_radius + sin(deg2rad(67.5))*$corner_radius,
		$left + $width - $corner_radius, $top + $height,

		$left + $corner_radius, $top + $height,
		$left + $corner_radius - cos(deg2rad(67.5))*$corner_radius, $top + $height - $corner_radius + sin(deg2rad(67.5))*$corner_radius,
		$left + $corner_radius - cos(deg2rad(45))*$corner_radius, $top + $height - $corner_radius + sin(deg2rad(45))*$corner_radius,
		$left + $corner_radius - cos(deg2rad(22.5))*$corner_radius, $top + $height - $corner_radius + sin(deg2rad(22.5))*$corner_radius,
		$left, $top + $height - $corner_radius

	);

	$rectangle = imagefilledpolygon($bg, $points_array, 20, $rectangle_color);

	$text_color = imagecolorallocatealpha($bg, $text_r, $text_g, $text_b, 0);
	
	imagettftext($bg, $fontsize, 0, $left + $padding_x, $top +  $fontadjust + $padding_y, $text_color, $font, $text);
	
	imagecopy($background, $bg, $x,$y, 0, 0, $corner_radius+ $width, $corner_radius + $height);
 
	return $background; 
} 
 
 
function gd_apply_graphics($background, $brand, $amount,$x,$y,$w,$h,$layer_r)
{
 	 
 
	$mag = $brand;
	$brand = basename($brand);

	/*	exit("monte carlo $brand");*/
 		 $picture = explode('.',$brand);
		 
         $ext = strtolower($picture[1]);
		 
	 
	switch ($ext)
{
	case 'gif':
		// We will be converting GIFs to PNGs to avoid transparency issues when resizing GIFs
		// This is maybe not the ideal solution, but IE6 can suck it
		$creationFunction	= 'ImageCreateFromGif';
		$outputFunction		= 'ImagePng';
		$mime				= 'image/png'; // We need to convert GIFs to PNGs
		$doSharpen			= FALSE;
		$quality			= round(10 - ($quality / 10)); // We are converting the GIF to a PNG and PNG needs a compression level of 0 (no compression) through 9
	break;
	
	case 'png':
	
		$creationFunction	= 'ImageCreateFromPng';
		$outputFunction		= 'ImagePng';
		$doSharpen			= FALSE;
		$quality			= round(10 - ($quality / 10)); // PNG needs a compression level of 0 (no compression) through 9
	break;
	
	default:
		$creationFunction	= 'ImageCreateFromJpeg';
		$outputFunction	 	= 'ImageJpeg';
		$doSharpen			= FALSE;
	break;
}
	$background2Rotation = (180+$layer_r) + 180;
 		$brand = 'v/uploads/layouts/' . $brand;
		 
		$brand = $creationFunction($brand);
	
	$foto2W 		= imagesx($brand); 
	$foto2H 		= imagesy($brand);

if(!empty($_GET['width'])){
		$newWidth= $_GET['width']; 
	$brand_width = $newWidth;   
	$brand_height = $newWidth; 
	$w = $newWidth;   
	$h = $newWidth;
 }

	$background2W	= $w;
	$background2H 	= $h;

	$background2TOP = $y;
	$background2LEFT= $x;

	$background2 	= imagecreatetruecolor($background2W,$background2H);
	$trans_colour 	= imagecolorallocatealpha($background2, 0, 0, 0, 127);
	imagefill($background2, 0, 0, $trans_colour);

	imagecopyresampled($background2, $brand, 0, 0, 0, 0, $background2W, $background2H, $foto2W, $foto2H);
	 
	
	$background2 	= imagerotate($background2,$background2Rotation, -1,0);
	/*after rotating calculate the difference of new height/width with the one before*/
	$extraTop		=(imagesy($background2)-$background2H)/2;
	$extraLeft		=(imagesx($background2)-$background2W)/2;

	imagecopy($background, $background2,$background2LEFT-$extraLeft, $background2TOP-$extraTop, 0, 0, imagesx($background2), imagesy($background2));	 
	/*$amount = transparency($amount);*/
		/*imagecopymerge($background, $background2,$background2LEFT-$extraLeft, $background2TOP-$extraTop, 0, 0, imagesx($background2), imagesy($background2),$amount);*/
	
	
	
	
	return $background;
}

function transparency($value)
{
 switch ($value) {
case "100":
$value ="0";
break;

case "99":
$value ="1";
break;

case "98":
$value ="2";
break;

case "97":
$value ="3";
break;

case "96":
$value ="4";
break;

case "95":
$value ="5";
break;

case "94":
$value ="6";
break;

case "93":
$value ="7";
break;

case "92":
$value ="8";
break;

case "91":
$value ="9";
break;

case "90":
$value ="10";
break;

case "89":
$value ="11";
break;

case "88":
$value ="12";
break;

case "87":
$value ="13";
break;

case "86":
$value ="14";
break;

case "85":
$value ="15";
break;

case "84":
$value ="16";
break;

case "83":
$value ="17";
break;

case "82":
$value ="18";
break;

case "81":
$value ="19";
break;

case "80":
$value ="20";
break;

case "79":
$value ="21";
break;

case "78":
$value ="22";
break;

case "77":
$value ="23";
break;

case "76":
$value ="24";
break;

case "75":
$value ="25";
break;

case "74":
$value ="26";
break;

case "73":
$value ="27";
break;

case "72":
$value ="28";
break;

case "71":
$value ="29";
break;

case "70":
$value ="30";
break;

case "69":
$value ="31";
break;

case "68":
$value ="32";
break;

case "67":
$value ="33";
break;

case "66":
$value ="34";
break;

case "65":
$value ="35";
break;

case "64":
$value ="36";
break;

case "63":
$value ="37";
break;

case "62":
$value ="38";
break;

case "61":
$value ="39";
break;

case "60":
$value ="40";
break;

case "59":
$value ="41";
break;

case "58":
$value ="42";
break;

case "57":
$value ="43";
break;

case "56":
$value ="44";
break;

case "55":
$value ="45";
break;

case "54":
$value ="46";
break;

case "53":
$value ="47";
break;

case "52":
$value ="48";
break;

case "51":
$value ="49";
break;

case "50":
$value ="50";
break;

case "49":
$value ="51";
break;

case "48":
$value ="52";
break;

case "47":
$value ="53";
break;

case "46":
$value ="54";
break;

case "45":
$value ="55";
break;

case "44":
$value ="56";
break;

case "43":
$value ="57";
break;

case "42":
$value ="58";
break;

case "41":
$value ="59";
break;

case "40":
$value ="60";
break;

case "39":
$value ="61";
break;

case "38":
$value ="62";
break;

case "37":
$value ="63";
break;

case "36":
$value ="64";
break;

case "35":
$value ="65";
break;

case "34":
$value ="66";
break;

case "33":
$value ="67";
break;

case "32":
$value ="68";
break;

case "31":
$value ="69";
break;

case "30":
$value ="70";
break;

case "29":
$value ="71";
break;

case "28":
$value ="72";
break;

case "27":
$value ="73";
break;

case "26":
$value ="74";
break;

case "25":
$value ="75";
break;

case "24":
$value ="76";
break;

case "23":
$value ="77";
break;

case "22":
$value ="78";
break;

case "21":
$value ="79";
break;

case "20":
$value ="80";
break;

case "19":
$value ="81";
break;

case "18":
$value ="82";
break;

case "17":
$value ="83";
break;

case "16":
$value ="84";
break;

case "15":
$value ="85";
break;

case "14":
$value ="86";
break;

case "13":
$value ="87";
break;

case "12":
$value ="88";
break;

case "11":
$value ="89";
break;

case "10":
$value ="90";
break;

case "9":
$value ="91";
break;

case "8":
$value ="92";
break;

case "7":
$value ="93";
break;

case "6":
$value ="94";
break;

case "5":
$value ="95";
break;

case "4":
$value ="96";
break;

case "3":
$value ="97";
break;

case "2":
$value ="98";
break;

case "1":
$value ="99";
break;

case "0":
$value ="100";
break;

default:
$value ="100";
}

 
	return $value;
}
/** Apply a PNG overlay */
 
 /** Apply a PNG overlay */
function gd_apply_overlay2($background, $brand, $amount,$x,$y)
{

 
		 $picture = explode('.',$brand);
         $ext = strtolower($picture[1]);
		 
	switch ($ext)
{
	case 'gif':
		// We will be converting GIFs to PNGs to avoid transparency issues when resizing GIFs
		// This is maybe not the ideal solution, but IE6 can suck it
		$creationFunction	= 'ImageCreateFromGif';
		$outputFunction		= 'ImagePng';
		$mime				= 'image/png'; // We need to convert GIFs to PNGs
		$doSharpen			= FALSE;
		$quality			= round(10 - ($quality / 10)); // We are converting the GIF to a PNG and PNG needs a compression level of 0 (no compression) through 9
	break;
	
	case 'png':
	
		$creationFunction	= 'ImageCreateFromPng';
		$outputFunction		= 'ImagePng';
		$doSharpen			= FALSE;
		$quality			= round(10 - ($quality / 10)); // PNG needs a compression level of 0 (no compression) through 9
	break;
	
	default:
		$creationFunction	= 'ImageCreateFromJpeg';
		$outputFunction	 	= 'ImageJpeg';
		$doSharpen			= FALSE;
	break;
}	 
 
 	$width =600;$height =600;
	$photoFrame2 = imagecreatetruecolor($width, $height);
	imagealphablending($photoFrame2, TRUE);
	imagesavealpha($photoFrame2, true);
 	$trans_colour = imagecolorallocatealpha($photoFrame2,  0, 0, 0, 127);
	imagefilledrectangle($photoFrame2, 0, 0, $width, $height, $trans_colour);
	$brand = 'v/uploads/gthumbs/' . $brand . '';
	$photo2 = $creationFunction($brand);
	imagecopyresampled($photoFrame2, $photo2, 0, 0, 0,0, $width, $height, $width, $height);
	$photoFrame = imagecreatetruecolor($width, $height);
	imagecopy($photoFrame, $background, 0, 0, 0, 0, $width, $height);
	imagecopy($photoFrame, $photoFrame2, 0, 0, 0, 0, $width, $height);
	imagecopymerge($background, $photoFrame, 0, 0, 0, 0, $width, $height, $amount); 
	imagedestroy($photoFrame); 

	
	return $background;
}

function gd_apply_overlay4($background, $brand, $amount)
{


$picture = explode('.',$brand);
         $ext = strtolower($picture[1]);
		 
	switch ($ext)
{
	case 'gif':
		// We will be converting GIFs to PNGs to avoid transparency issues when resizing GIFs
		// This is maybe not the ideal solution, but IE6 can suck it
		$creationFunction	= 'ImageCreateFromGif';
		$outputFunction		= 'ImagePng';
		$mime				= 'image/png'; // We need to convert GIFs to PNGs
		$doSharpen			= FALSE;
		$quality			= round(10 - ($quality / 10)); // We are converting the GIF to a PNG and PNG needs a compression level of 0 (no compression) through 9
	break;
	
	case 'png':
	
		$creationFunction	= 'ImageCreateFromPng';
		$outputFunction		= 'ImagePng';
		$doSharpen			= FALSE;
		$quality			= round(10 - ($quality / 10)); // PNG needs a compression level of 0 (no compression) through 9
	break;
	
	default:
		$creationFunction	= 'ImageCreateFromJpeg';
		$outputFunction	 	= 'ImageJpeg';
		$doSharpen			= FALSE;
	break;
}	 
 	$width =600;$height =600;
	$photoFrame2 = imagecreatetruecolor($width, $height);
	imagealphablending($photoFrame2, false);
	imagesavealpha($photoFrame2, true);
 	$trans_colour = imagecolorallocatealpha($photoFrame2,  0, 0, 0, 127);
	imagefilledrectangle($photoFrame2, 0, 0, $width, $height, $trans_colour);
	$brand = 'v/uploads/gthumbs/' . $brand . '';
	$photo2 = $creationFunction($brand);
	imagecopyresampled($photoFrame2, $photo2, 0, 0, 0,0, $width, $height, $width, $height);
	$photoFrame = imagecreatetruecolor($width, $height);
	imagecopy($photoFrame, $background, 0, 0, 0, 0, $width, $height);
	imagecopy($photoFrame, $photoFrame2, 0, 0, 0, 0, $width, $height);
	imagecopymerge($background, $photoFrame, 0, 0, 0, 0, $width, $height, $amount); 
	imagedestroy($photoFrame); 
	
	return $background;
}
function gd_apply_graphic_text($background, $brand, $amount,$x,$y)
{

 

 
		 $picture = explode('.',$brand);
         $ext = strtolower($picture[1]);
		 
	switch ($ext)
{
	case 'gif':
		// We will be converting GIFs to PNGs to avoid transparency issues when resizing GIFs
		// This is maybe not the ideal solution, but IE6 can suck it
		$creationFunction	= 'ImageCreateFromGif';
		$outputFunction		= 'ImagePng';
		$mime				= 'image/png'; // We need to convert GIFs to PNGs
		$doSharpen			= FALSE;
		$quality			= round(10 - ($quality / 10)); // We are converting the GIF to a PNG and PNG needs a compression level of 0 (no compression) through 9
	break;
	
	case 'png':
	
		$creationFunction	= 'ImageCreateFromPng';
		$outputFunction		= 'ImagePng';
		$doSharpen			= FALSE;
		$quality			= round(10 - ($quality / 10)); // PNG needs a compression level of 0 (no compression) through 9
	break;
	
	default:
		$creationFunction	= 'ImageCreateFromJpeg';
		$outputFunction	 	= 'ImageJpeg';
		$doSharpen			= FALSE;
	break;
}	 
 
 	$width =600;$height =600;
	$photoFrame2 = imagecreatetruecolor($width, $height);
	imagealphablending($photoFrame2, false);
	imagesavealpha($photoFrame2, true);
 	$trans_colour = imagecolorallocatealpha($photoFrame2,  0, 0, 0, 127);
	imagefilledrectangle($photoFrame2, 0, 0, $width, $height, $trans_colour);
	$brand = 'v/uploads/text/' . $brand . '';
	$photo2 = $creationFunction($brand);
	imagecopyresampled($photoFrame2, $photo2, 0, 0, 0,0, $width, $height, $width, $height);
	$photoFrame = imagecreatetruecolor($width, $height);
	imagecopy($photoFrame, $background, 0, 0, 0, 0, $width, $height);
	imagecopy($photoFrame, $photoFrame2, 0, 0, 0, 0, $width, $height);
	imagecopymerge($background, $photoFrame, 0, 0, 0, 0, $width, $height, $amount); 
	imagedestroy($photoFrame); 

	
	return $background;
	
	} 
	
	
	
	
	function gd_apply_overlay6($background, $brand, $amount)
{


$picture = explode('.',$brand);
         $ext = strtolower($picture[1]);
		 
	switch ($ext)
{
	case 'gif':
		// We will be converting GIFs to PNGs to avoid transparency issues when resizing GIFs
		// This is maybe not the ideal solution, but IE6 can suck it
		$creationFunction	= 'ImageCreateFromGif';
		$outputFunction		= 'ImagePng';
		$mime				= 'image/png'; // We need to convert GIFs to PNGs
		$doSharpen			= FALSE;
		$quality			= round(10 - ($quality / 10)); // We are converting the GIF to a PNG and PNG needs a compression level of 0 (no compression) through 9
	break;
	
	case 'png':
	
		$creationFunction	= 'ImageCreateFromPng';
		$outputFunction		= 'ImagePng';
		$doSharpen			= FALSE;
		$quality			= round(10 - ($quality / 10)); // PNG needs a compression level of 0 (no compression) through 9
	break;
	
	default:
		$creationFunction	= 'ImageCreateFromJpeg';
		$outputFunction	 	= 'ImageJpeg';
		$doSharpen			= FALSE;
	break;
}	 
 	$width =600;$height =600;
	$photoFrame2 = imagecreatetruecolor($width, $height);
	imagealphablending($photoFrame2, false);
	imagesavealpha($photoFrame2, true);
 	$trans_colour = imagecolorallocatealpha($photoFrame2,  0, 0, 0, 127);
	imagefilledrectangle($photoFrame2, 0, 0, $width, $height, $trans_colour);
	$brand = 'brands/' . $brand . '';
	$photo2 = $creationFunction($brand);
	imagecopyresampled($photoFrame2, $photo2, 0, 0, 0,0, $width, $height, $width, $height);
	$photoFrame = imagecreatetruecolor($width, $height);
	imagecopy($photoFrame, $background, 0, 0, 0, 0, $width, $height);
	imagecopy($photoFrame, $photoFrame2, 0, 0, 0, 0, $width, $height);
	imagecopymerge($background, $photoFrame, 0, 0, 0, 0, $width, $height, $amount); 
	imagedestroy($photoFrame); 
	
	return $background;
}
/** Apply a PNG overlay */
function hex_to_rgb($hex) {
    // remove '#'
    if(substr($hex,0,1) == '#')
        $hex = substr($hex,1) ;

    // expand short form ('fff') color to long form ('ffffff')
    if(strlen($hex) == 3) {
        $hex = substr($hex,0,1) . substr($hex,0,1) .
               substr($hex,1,1) . substr($hex,1,1) .
               substr($hex,2,1) . substr($hex,2,1) ;
    }

    if(strlen($hex) != 6)
        fatal_error('Error: Invalid color "'.$hex.'"') ;

    // convert from hexidecimal number systems
    $rgb['red'] = hexdec(substr($hex,0,2)) ;
    $rgb['green'] = hexdec(substr($hex,2,2)) ;
    $rgb['blue'] = hexdec(substr($hex,4,2)) ;

    return $rgb ;
}


function fatal_error($message)
{
    // send an image
    if(function_exists('ImageCreate'))
    {
        $width = ImageFontWidth(5) * strlen($message) + 10 ;
        $height = ImageFontHeight(5) + 10 ;
        if($image = ImageCreate($width,$height))
        {
            $background = ImageColorAllocate($image,255,255,255) ;
            $text_color = ImageColorAllocate($image,0,0,0) ;
            ImageString($image,5,5,5,$message,$text_color) ;
            header('Content-type: image/png') ;
            ImagePNG($image) ;
            ImageDestroy($image) ;
            exit ;
        }
    }

    // send 500 code
    header("HTTP/1.0 500 Internal Server Error") ;
    print($message) ;
    exit ;
}
/*if(!$image || !$box)
{
    fatal_error('Error: The server could not create this image.') ;
}
*/ 
 function dummyText()
{
	if(!empty($_GET['context']))
	{
	$text = $_GET['context']." *".$_GET['cl']; 
	 
	
	}
	else
	{
			$text = "How Are You Feeling Today?  *".$_GET['cl']; 
	}

	
	
		 
	  return $text;
	  } 
	  
	   function realText()
{
	 $text = mysqli_real_escape_string($link,$_GET['context']) ;
	 $text = str_replace("*thebrand","",$text) ;	
	 $text = str_replace("thebrand","",$text) ;	 	 
	$text  = removeslashes($text);	
	return $text;
	  }
	  
	  
	    
	 
	 
 function username()
{
	$nani = $_SESSION["user"]; 
	
	if(!empty($_GET['nani']))
	{
	$nani = $_GET['nani']; 	
	 
	
	}
		if(!empty($_GET['newnani']))
	{
	$nani = $_GET['newnani']; 	
	 
	
	}

	
				if(!empty($_GET['convoId']) && $_GET['context'] != "undefined")
					{
					   $convoId = $_GET['convoId']; 	
					$rs_settings = mysqli_query($link,"select * from tweets where id=$convoId");	
								 while ($row_settings = mysqli_fetch_array($rs_settings)) {
								 
							  $un = strtolower($row_settings['screen_name']);
							  
							return removeslashes($un);	
							  
							 }
					
					}
					else
					{
						$rs_settings = mysqli_query($link,"select * from users where catalogid=$nani");

									 while ($row_settings = mysqli_fetch_array($rs_settings)) {
									 
								  $un = strtolower($row_settings['user_name']);
								  
								return removeslashes($un);	
								  
								 }
					}
	
	
 	 
		 }

 function user()
{
	$nani = $_SESSION["user"]; 
	
	if(!empty($_GET['nani']))
	{
	$nani = $_GET['nani']; 	
	 
	
	}
			if(!empty($_GET['newnani']))
	{
	$nani = $_GET['newnani']; 	
	 
	
	}


						if(!empty($_GET['convoId']) && $_GET['context'] != "undefined")
					{
					   $convoId = $_GET['convoId'];
					   
					   $rs_settings = mysqli_query($link,"select * from campaign_message where campaignid=$convoId");	
								 while ($row_settings = mysqli_fetch_array($rs_settings)) {
									$newsid = ucwords($row_settings['newsid']); 
									 if(!empty($newsid)){$ca = ""; return removeslashes($ca);exit();}
									 else
									 {
										 $rs_settings = mysqli_query($link,"select * from tweets where id=$convoId");	
								 while ($row_settings = mysqli_fetch_array($rs_settings)) {
								 
							  $ca = ucwords($row_settings['user_name']);
						 
							return removeslashes($ca);	
							  
							 }}
									 
								 }
					
					
					}
					else
					{
						$rs_settings = mysqli_query($link,"select * from users where catalogid=$nani");
									 while ($row_settings = mysqli_fetch_array($rs_settings)) {
									 
								 	   $ca =  $row_settings['catalogname'] ;
	  									return removeslashes($ca);
								  
								 }
					}


 	  }

 function yanani($yanani)
{
	 
 $rs_settings = mysqli_query($link,"select * from users where catalogid=$yanani"); 
		 while ($row_settings = mysqli_fetch_array($rs_settings)) {
		 
	  $user_name = strtolower($row_settings['user_name']);
	  return removeslashes($user_name);
	  
	 } }
 function slug()
{
	$nani = $_SESSION["user"]; 
	
	if(!empty($_GET['nani']))
	{
	$nani = $_GET['nani']; 	
	 
	
	}
			if(!empty($_GET['newnani']))
	{
	$nani = $_GET['newnani']; 	
	 
	
	}

	
 	$rs_settings = mysqli_query($link,"select * from users where catalogid=$nani"); 
		 while ($row_settings = mysqli_fetch_array($rs_settings)) {
		 
	  return $slug = strtolower($row_settings['slug']);
	  
	 } }

 function bio()
{
	$nani = $_SESSION["user"]; 
	
	if(!empty($_GET['nani']))
	{
	$nani = $_GET['nani']; 	
	 
	
	}
			if(!empty($_GET['newnani']))
	{
	$nani = $_GET['newnani']; 	
	 
	
	}

	
 	$rs_settings = mysqli_query($link,"select * from users where catalogid=$nani"); 
		 while ($row_settings = mysqli_fetch_array($rs_settings)) {
			 $description = strtolower($row_settings['description']);
			 if(empty($description)){ $description=  "Visit thebrand.co.ke/".$row_settings['user_name']." for updates";} 
			 else{
				 $description = strtolower($row_settings['description']);
				 }
		 
	  
	  return  removeslashes($description);
	  
	 } }

function write($brand,$position)
{ 
	$themeid = $_GET['theme_id'];
 $query = mysqli_query("SELECT * FROM `layerorder` WHERE themeid='$themeid' and position='$position'") or die(mysql_error());
	   $row=mysqli_fetch_array($query);
	  
	  $name= $row['name'];
	  
 
	$layerx = $row['layerx'];;
	$layery = $row['layery'];
	
				
				$context= preg_replace('/\*(\\w+)/', "", $_GET['context']);
				$context = urlencode($context); 
				$type = "Caption";
				$parts = parse_url($name);
				parse_str($parts['query'], $query);
				 $remove = $query['text'];
				 
				  $exec =  "&S=1&pichaNi=".$themeid."CaptionLayer&text=$context&position=$position&x=$layerx&y=$layery&type=caption";
				$newword =  $context.$exec;
			
				   $newString =  $name.$exec;
				/*  exit($newString);*/
				
					$data = array(array(),array());
					 $data[0]['url']  = $newString;
					$data[0]['post'] = array();
					$data[0]['post']['q']   = 'YahooDemo';
					$r =  multiRequestX($data);
	 $brand =  $themeid."CaptionLayer.png";
	 $url = basename($brand);
	 
	return $url;
	
	
	
}
 function profilepicture()
{
	$nani = $_SESSION["user"]; 
	
	if(!empty($_GET['nani']))
	{
	$nani = $_GET['nani']; 	
	 
	
	}
			if(!empty($_GET['newnani']))
	{
	$nani = $_GET['newnani']; 	
	 
	
	}

	
 	$rs_settings = mysqli_query($link,"select * from profilepicture where catalogid=$nani and type='1' limit 0,1"); 
		 while ($row_settings = mysqli_fetch_array($rs_settings)) {
		 
	  return $picture = strtolower($row_settings['picture']);
	  
	 } }

 function findStartag($startag)
{
 	$rs_settings = mysqli_query($link,"select * from profilepicture where title='$startag' limit 0,1"); 
		 while ($row_settings = mysqli_fetch_array($rs_settings)) {
		 $newsid = $row_settings['id'];
		 $yanani = $row_settings['catalogid'];
		 $nani = $_GET['nani'];
		 if($nani!=$yanani)
		 {
			 $viewnum = $row_settings['viewnum'];
		 $viewnum = $viewnum+1;
		 mysqli_query("update profilepicture set viewnum=$viewnum where id='$newsid'");  
			 
			 
			 }
		
		 $picture = explode('.',$row_settings['picture']);
         $picture = $picture[0];
		 $picture = $row_settings['picture'];
		 $theme = $row_settings['description'];
		 $overlay = $row_settings['overlay'];
		 $yanani = $row_settings['catalogid'];
		 $fx = $row_settings['fx'];
		 $x = $row_settings['x'];
		 $y = $row_settings['y'];
	  return $picture."|".$theme."|".$overlay."|".$yanani."|".$x."|".$y."|".$fx."|";
	  
	 } }

 function openGallery($startag)
{
 	$rs_settings = mysqli_query($link,"select * from profilepicture where title='$startag' and type=3  limit 0,1"); 
		 while ($row_settings = mysqli_fetch_array($rs_settings)) {
		 $newsid = $row_settings['id'];
		 $yanani = $row_settings['catalogid'];
		 $nani = $_GET['nani'];
		 if($nani!=$yanani)
		 {
			 $viewnum = $row_settings['viewnum'];
		 $viewnum = $viewnum+1;
		 mysqli_query("update profilepicture set viewnum=$viewnum where id='$newsid'");  
			 
			 
			 }
		
		 $picture = explode('.',$row_settings['picture']);
         $picture = $picture[0];
         $picture = $row_settings['picture'];
		 $theme = $row_settings['description'];
		 $overlay = $row_settings['overlay'];
		 $yanani = $row_settings['catalogid'];
		 $fx = $row_settings['fx'];
		 $x = $row_settings['x'];
		 $y = $row_settings['y'];
	  return $picture."|".$theme."|".$overlay."|".$yanani."|".$x."|".$y."|".$fx."|";
	  
	 } }

 function AppOwner()
{
	$AppNo = $_GET['AppNo']; 
	 
 	$rs_settings = mysqli_query($link,"select * from users where catalogid=$AppNo"); 
		 while ($row_settings = mysqli_fetch_array($rs_settings)) {
		 
		  return $cat = strtolower($row_settings['catalogname']);
	  
	 } }
	 function country()
{
	$nani = $_SESSION["user"]; 
	
	if(!empty($_GET['nani']))
	{
	$nani = $_GET['nani']; 	
	 
	
	}
	
	
 	$rs_settings = mysqli_query($link,"select * from users where catalogid=$nani"); 
		 while ($row_settings = mysqli_fetch_array($rs_settings)) {
		 
	  return $country = strtolower($row_settings['country']);
	  
	 } }
	  

if ($_GET['gratitude'] == "start")  {
$uploaddir = 'v/uploads/raw/';
$image ="images/gratitude.jpg";
$date	= md5(date('D, d M Y H:i:s'));
$upload =  $date.basename($image);

$uploadfile = $uploaddir .$upload; 

 copy($image,$uploadfile);
 
 $user      = user();
$owner     = AppOwner();
 $AppNo = $_GET['AppNo'];
 $nani = $_GET['nani'];


$db->addgratitude($user,$owner,$AppNo,$nani,$upload);
$pic = $upload;
 
}	 
	 
	

 
 
 function showUpdate($nani) 
	{

/*error_reporting(0);*/
include_once 'real/service/social/includes/tolink.php';
include_once 'real/service/social/includes/textlink.php';
include_once 'real/service/social/includes/htmlcode.php';
include_once 'real/service/social/includes/Expand_URL.php';
require("const.inc.php");   
 $newquery = mysqli_query("SELECT M.msg_id, M.newsid, M.catalogid_fk, M.original,M.isdisplay,M.episodeid,M.yanani, M.message, M.created, U.user_name,U.slug,M.uploads,M.type, U.user_name FROM reporta M, users U where M.catalogid_fk=U.catalogid and M.catalogid_fk='$nani' order by M.msg_id desc limit 1 ");
  $data = mysqli_fetch_array($newquery);
		

if(!$data)
{
	
	exit("sent already......");}

if($data)
{
	 $url=$data['message']; 
$returns = 'none';
if(eregi("youtu",$url) or eregi("youtube",$url)){
        if(eregi("v=",$url))
    $splits = explode("=",$url);
    else
    $splits = explode("be/",$url);

        if(!empty($splits[1])){
			if(preg_match("/feature/i", $splits[1])){
			$splits[1] = str_replace("&feature","",$splits[1]);	
			}
                $returns = '<iframe width="100%" height="400" src="http://www.youtube.com/embed/'.$splits[1].'" frameborder="0"></iframe>';
        }
} else if(eregi("vimeo",$url)){
        $splits = explode("com/",$url);
        $returns = '<iframe src="http://player.vimeo.com/video/'.$splits[1].'?title=0&amp;byline=0&amp;portrait=0" width="100%" height="400" frameborder="0"></iframe>';
}
	
	 
 $msg_id=$data['msg_id'];
 $orimessage=$data['message'];

 $message=$db-> $data['message'] ; 
 $message= preg_replace('/\*(\\w+)/', "",$message );
 $message=tolink(htmlcode($message));
 
  $time=$data['created'];  $msg_created=$data['created'];
$mtime=date("c", $time);
  $user_name=$data['user_name'];
 $profile=$data['slug'];
  $uploads=$data['uploads'];
 $msg_catalogid=$data['catalogid_fk'];
$msg_yanani=$data['yanani'];
  $msg_slug=$data['slug'];
  $msg_slug=$data['slug'];
  $nani=$data['type'];
  $photoDisplay=$data['original'];
  
$msg_newsid=$data['msg_id'];
  if($nani==13) { $msg_newsid=$data['newsid'];$msg_id=$data['newsid']; }
  $forChannel=$data['msg_id'];
    $forText=$data['msg_id'];
	 $forVideo=$data['msg_id'];
	 $forLove=$data['msg_id'];
   $msgidLove=$data['msg_id'];
	 $photoDisplay=$data['original'];
$isdisplay=$data['isdisplay'];
  $episodeid=$data['episodeid'];
$actualID=$data['msg_id'];
 
 
  if(!empty($_SESSION['TwitterUsername']))
		{
			include 'twitter/EpiTwitter/EpiCurl.php';
			include 'twitter/EpiTwitter/EpiOAuth.php';
			include 'twitter/EpiTwitter/EpiTwitter.php';
			include 'twitter/EpiTwitter/TwitterConfig.php';
			include("Connections/videoondemand.php");
			include("twitter/db.php");
			
			$message=mysql_real_escape_string($orimessage);
			 $message=stripslashes($message);
			$pic = " $siteaddress3/taswira.php?width=500&quality=70&image=/v/uploads/raw/$photoDisplay";  
 
 
			  $TwitterUsername=$_SESSION['TwitterUsername'];
			$tw_sql=mysqli_query($connection,"SELECT oauth_token,oauth_token_secret FROM users WHERE tel='$msg_catalogid'");
			$row=mysqli_fetch_array($tw_sql,MYSQLI_ASSOC);
			$oauth_token=$row["oauth_token"];
			$oauth_token_secret=$row["oauth_token_secret"];
			 
			$Twitter = new EpiTwitter($consumer_key, $consumer_secret);
			$Twitter->setToken($oauth_token,$oauth_token_secret);
			$status=$Twitter->post_statusesUpdate(array('status' => $message.$pic));
			/*echo $status->id_str;*/
			 
			}	
?>

  <img src="<?php echo $siteaddress3 ?>taswira.php?width=600&quality=100&image=/v/uploads/raw/<?php echo $photoDisplay ?>" width="100%"  /> 
<?php
}	
else

{?>
<?php /*?>	 Duplicate Post<?php */?><img src="<?php echo $siteaddress3 ?>taswira.php?width=600&quality=100&image=/v/uploads/raw/<?php echo $photoDisplay ?>" width="100%"  /> 
 
	<?php }		 
			 
      
       
    } 
 
 
 
 
 
 
 
 
 
 
 
 
	  	
	
 

 if ($_GET['gratitude'] == "posted")  {

if (!empty($_GET['context'])) 
{
 $text = realText();
 
}
else
{
	 $text = mysqli_real_escape_string($link,$_GET['cl']);
}
 
 
preg_match('/\>(\\w+)/',$_GET['context'],$vida);
$vida =$vida[1];
//is it video or not
//is it video or not
if ($vida  == "video") 
{ //it is video hurraaaay

include("mags/video.php"); 
exit();}



if ($vida != "video") 
{ //its not
$uploaddir = 'v/uploads/raw/';

$picture     = profilepicture();
if(!empty($picture)) 
{
	
	
					if(!empty($_GET["postDirect"])) 
				{
					$image ="v/uploads/raw/$picture";
				}
				else
				{
					$image ="v/uploads/gthumbs/$picture";
					}
					
	
	
}
else
{
$picme = rand(1,10);
if($picme == 1) { $image ="images/backgrounds/bg-4.jpg"; } 
if($picme == 2) { $image ="images/backgrounds/bold.jpg";} 
if($picme == 3) { $image ="images/backgrounds/dusk.jpg"; } 
if($picme == 4) { $image ="images/backgrounds/bg-2.jpg"; } 
if($picme == 5) { $image ="images/backgrounds/bg-3.jpg"; } 
if($picme == 6) { $image ="images/backgrounds/frost.jpg"; } 
if($picme == 7) { $image ="images/backgrounds/sky.jpg";} 
if($picme == 8) { $image ="images/backgrounds/sunset.jpg"; } 
if($picme == 9) { $image ="images/backgrounds/sunset2.jpg"; } 
if($picme == 10) { $image ="images/backgrounds/sunset3.jpg"; }
/*$image ="images/backgrounds/bg-4.jpg"; */
} 
 

$date	= md5(time());
/*$upload =  $date.basename($image);*/
$upload =  $date.".jpg";

			 	

$uploadfile = $uploaddir .$upload; 



if (!empty($_GET['cl'])) 

{ 
$pic =$_GET['pic'];
			 	


 gd_filter_image('v/uploads/gthumbs/' . $pic, $_GET['filter']); }


else
{
	copy($image,$uploadfile);  
}
	


 $user      = user();
$owner     = AppOwner();
 $AppNo = mysqli_real_escape_string($link,$_GET['AppNo']);
 $nani = mysqli_real_escape_string($link,$_GET['nani']);
		
if (!empty($_GET['context'])) 
		{
		 $text = realText();
		 $text = str_replace("\n" , ' ',$context);
		  $text = str_replace("\r" , ' ',$context);
$uploads="";
 
 if (empty($_GET['display'])) {	

$db->Insert_UpdateX($nani,$text,$uploads,$AppNo,$upload,$owner); 		
	
 }
	
		}		
		
	if (!empty($_GET['cl'])) 
		{
		$text = dummyText(); 
		}		
			
	 
		
 
$pic = $upload;

} 
 


 
if ($pic && $_GET['filter']) {

 if (!empty($_GET['fire'])) {
 
	$AppNo = mysqli_real_escape_string($link,$_GET['AppNo']);
	$cl = mysqli_real_escape_string($link,$_GET['cl']);
	$overlay = mysqli_real_escape_string($link,$_GET['overlay']);
	$pic = $_GET['pic'];
	$x = $_GET['x'];
	$fx = $_GET['fx'];
	$mytitle = $_GET['mytitle'];
	$y = $_GET['y'];
	$msg_id = $_GET['msg_id'];
	$msg_id = $db->base64url_decode($msg_id);
	$mytitle = $_GET['mytitle'];
	$fx = $_GET['fx'];
	
	
	
	
	
	if(!empty($fx))
	{
 
 
		$db->mag8($pic,$fx,$msg_id,$ren);
		
	}
		else
	{
		$db->mag7($pic,$AppNo,$cl,$overlay,$mytitle,$x,$y,$msg_id);
		}



 
	}

		
 $mag = $_GET['mag'];	
 	$id = substr($pic, 5, 1);
	
	
	if (!empty($_GET['cl'])) { 
$pic =$_GET['pic'];
 

				
/*gd_filter_image($image, "blank"); */
gd_filter_image('v/uploads/gthumbs/' . $pic, $_GET['filter']); }
else
{
	gd_filter_image('v/uploads/raw/' . $pic, $_GET['filter']);
}
	
	
	  

 //end no vida
 }	 

}



?>