<?
/*
resize & cache 이미지
*/
// testurl
// http://hd.yodition.com/lib/loadimg.php?fn=/ld4/mealimg/top1.jpg&w=50&h=50
include_once('libgods.php');

function outputimg($fn)
{
	header('Content-Type: image/jpeg');
	readfile($fn);
}
function loadimg()
{
	$a = $_REQUEST;
	$orgfn = '../'.$a[fn];
	//$orgfn = 'ld4/mealimg/top1.jpg';//$a[fn];
	$orgdir = dirname($orgfn);
	
	$w = $a[w];
	$h = $a[h];
	if (isset($w) && isset($h))
	{
		$dir = '../thumbnails/';			
		@mkdir($dir, 777, true);
		$fn = $dir."th-$w-$h-".md5($a[fn]).basename($orgfn);
		if (file_exists($fn))
		{
			outputimg($fn);
		} else
		{	
			$img = new SimpleImage();
			$img->load($orgfn);
			$img->resize($w, $h);
			$img->save($fn);
			outputimg($fn);			
		}	
	} else
	{	
		outputimg($orgfn);
	}
}

loadimg();
/*
(function(){
	loadimg();
})();
*/
?>