<?

	/*$sLabel = $_GET['LABEL'];*/
	$sCreate = $_GET['CREATE'];
	$sFile = $_GET['FILE'];
	$sFileName = $_GET['FILENAME'];
	$rootpath = "/var/www/vhosts/assets.jowood.com/httpdocs/thumbs/";
	
	$size = $_GET['size'];
	if(!$size)
		$size = 53;
	/*
	$sType = $_GET['TYPE'];
	$imausrichtung = 140;
	
				
	$sFile = md5($sLabel.$sFile);

	$sLabel = str_replace("(","( ",$sLabel);
	$sLabel = str_replace(")",") ",$sLabel);
	$sLabel = str_replace("&","& ",$sLabel);
			*/
	if(file_exists($sFileName."_thumb.jpg") && empty($sCreate))
	{
		header("Content-Type:image/jpg");
		readfile($sFileName."_thumb.jpg","r");
	} 
	else
	{ 
		

		$width = 120;
		$height = 90;

		
		$need_width  = 0;	
		$aFormat = getimagesize($sFile);
		$prop_width = $aFormat[0]/$width;
		$need_height = $aFormat[1]/$prop_width;
		if($need_height < $height)
		{
			$prop_height = $aFormat[1]/$height;
			$need_width = $aFormat[0]/$prop_height;
		}
		else
		{
			$need_width = $width;
		}
		
		
		//$cmd ="\"C:\\Program Files\\ImageMagick-6.3.4-Q16\\convert.exe\" ".$rootpath.$sFile.".jpg -resize ".($need_width+1)." -crop ".$width."x".$height."+1+1 -gravity center ".$rootpath.$sFile."_djmixesgeneratedthumb_".$size.".jpg";
		
		$cmd ='/usr/bin/convert '.escapeshellarg($sFile).' -resize '.($need_width+1).' -crop '.$width.'x'.$height.'+1+1 -gravity center '.escapeshellarg($rootpath.$sFileName).'_thumb.jpg';
		//echo $cmd;
		//exit;
		@exec(escapeshellcmd($cmd),$output,$return); 
		
		if($_GET['debug'] == "true")
		{
			print_r($output);
			print_r($return);
			exit;
		}
		header("Content-Type:image/jpg");
		
		readfile($sFileName."_thumb.jpg");
	
	} 
?>
