<?
if( !$board ) $board = $_GET[board];
if( !$index ) $index = $_GET[index];
if( !$no ) $no = $_GET[no];
if( !$index || !$board ) return;
$arrImgSize = array(
		'article' => array(
			'1' => array('80', '60')
			,'2' => array('160', '120')
			,'3' => array('221', '128')
			,'4' => array('234', '128')
			,'5' => array('691', '436')
			,'6' => array('560', '373')
			,'7' => array('229', '149')
			,'8' => array('308', '173')
			,'9' => array('632', '356')
		)
	);

if($no){
	$width = $arrImgSize[$board][$index][0]; 
	$height = $arrImgSize[$board][$index][1]; 
	if(!$width || !$height) return; 

	$fname = '/app/menu.mtn.co.kr/upload/'.$board.'/resize'.$width.'_'.$height.'/'.substr($no, 0, 4).'/'.substr($no, 4, 2).'/'.substr($no, 6, 2).'/'.$no;

	if( ($fp = @fopen($fname, 'r')) )
		fpassthru($fp);
	else  {

		$filename = '/app/menu.mtn.co.kr/upload/'.$board.'/'.substr($no, 0, 4).'/'.substr($no, 4, 2).'/'.substr($no, 6, 2).'/'.$no;


        @exec('mkdir /app/menu.mtn.co.kr/upload/'.$board.'/resize'.$width.'_'.$height.'/'.substr($no, 0, 4));
        @exec('chmod 755 /app/menu.mtn.co.kr/upload/'.$board.'/resize'.$width.'_'.$height.'/'.substr($no, 0, 4));
        
        @exec('mkdir /app/menu.mtn.co.kr/upload/'.$board.'/resize'.$width.'_'.$height.'/'.substr($no, 0, 4).'/'.substr($no, 4, 2));
		@exec('chmod 755 /app/menu.mtn.co.kr/upload/'.$board.'/resize'.$width.'_'.$height.'/'.substr($no, 0, 4).'/'.substr($no, 4, 2));
		@exec('mkdir /app/menu.mtn.co.kr/upload/'.$board.'/resize'.$width.'_'.$height.'/'.substr($no, 0, 4).'/'.substr($no, 4, 2).'/'.substr($no, 6, 2));
		@exec('chmod 755 /app/menu.mtn.co.kr/upload/'.$board.'/resize'.$width.'_'.$height.'/'.substr($no, 0, 4).'/'.substr($no, 4, 2).'/'.substr($no, 6, 2));

		@mkdir('/app/menu.mtn.co.kr/upload/'.$board.'/resize'.$width.'_'.$height.'/'.substr($no, 0, 4).'/'.substr($no, 4, 2), 0755);
		@mkdir('/app/menu.mtn.co.kr/upload/'.$board.'/resize'.$width.'_'.$height.'/'.substr($no, 0, 4).'/'.substr($no, 4, 2).'/'.substr($no, 6, 2), 0755);

		// Content type
		//header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 
		//header('Cache-Control: no-store, no-cache, must-revalidate'); 
		//header('Cache-Control: post-check=0, pre-check=0', FALSE); 
		//header('Pragma: no-cache'); 
		//header('Content-type: image/jpeg');

		// Get new dimensions
        
       	$new_width = $width;
		$new_height = $height;

        list($image_width, $image_height, $type) = getimagesize($filename);
	
       if ($width > 0 && $height > 0)
		{
			// ¼¶³×ÀÏ Å©±â ¾È¿¡ ¸ðµÎ Ç¥½Ã
			// ÀÌ¹ÌÁöÀÇ °¡Àå Å« ¸éÀ» ±âÁØÀ¸·Î ÁöÁ¤
			
            $side = ($image_width >= $image_height) ? 'width' : 'height'; 

			$thumb_x = $thumb_y = 0;
			if ($side == 'width')
			{
				$ratio = $image_width / $width;
				$thumb_width = $width;
				$thumb_height = floor($image_height / $ratio);
				$thumb_y = round(($height - $thumb_height) / 2);
			}
			else
			{
				$ratio = $image_height / $height;
				$thumb_width = floor($image_width / $ratio);
				$thumb_height = $height;
				$thumb_x = round(($width - $thumb_width) / 2);
			}
		 }
        
        
        
 
		// Resample
		$image_p = imagecreatetruecolor($new_width, $new_height);
        $backgroundColor = imagecolorallocate($image_p, 255, 255, 255);
        imagefill($image_p, 0, 0, $backgroundColor);

 
		switch ($type) {
			case 1:  //   png -> jpg
				$image = imagecreatefromgif($filename);
				break;
			case 3:  //   png -> jpg
				$image = imagecreatefrompng($filename);
				break;
			default:
				$image = imagecreatefromjpeg($filename);
				break;
		}
	 
        
		imagecopyresampled($image_p, $image, $thumb_x, $thumb_y, 0, 0, $thumb_width, $thumb_height, $image_width, $image_height);
         

		// Output
		//echo $image."|".$width."|".$height;
		@imagejpeg($image_p, $fname, 100);
		@imagedestroy($image_p); 
        
        
        
         

		if( ($fp = @fopen($fname, 'r')) ){
			fpassthru($fp);
			fclose($fp);
		} else
			echo ($_SERVER['SERVER_ADDR']);
		

	}
}

 

/*
	if ($width > 0 && $height > 0)
		{
			// ¼¶³×ÀÏ Å©±â ¾È¿¡ ¸ðµÎ Ç¥½Ã
			// ÀÌ¹ÌÁöÀÇ °¡Àå Å« ¸éÀ» ±âÁØÀ¸·Î ÁöÁ¤
			switch ($scale)
			{
				case SCALE_SHOW_ALL: $side = ($image_width >= $image_height) ? 'width' : 'height'; break;
				case SCALE_EXACT_FIT:
				default: $side = ($image_width / $width <= $image_height / $height) ? 'width' : 'height'; break;
			}

			$thumb_x = $thumb_y = 0;
			if ($side == 'width')
			{
				$ratio = $image_width / $width;
				$thumb_width = $width;
				$thumb_height = floor($image_height / $ratio);
				$thumb_y = round(($height - $thumb_height) / 2);
			}
			else
			{
				$ratio = $image_height / $height;
				$thumb_width = floor($image_width / $ratio);
				$thumb_height = $height;
				$thumb_x = round(($width - $thumb_width) / 2);
			}
		}
        
        
        */

?>
