<?
die;
if (isset($_GET['file'])){
	$fileName=$_GET['file'];
	$file=realpath("./img/arvores/".$fileName);
	if (file_exists($file)){
		// Content type
		header('Content-Type: image/jpeg');
		list($width, $height) = getimagesize($file);
		$newheight = 100;
		$newwidth = $newheight / $height  * $width;
		
		if (file_exists(realpath("./img/arvores/thumbs")."/".md5($fileName.$newwidth.$newheight))&& false){
			print file_get_contents(realpath("./img/arvores/thumbs")."/".md5($fileName.$newwidth.$newheight));	
		}else{
			
			$thumb = imagecreatetruecolor($newwidth, $newheight);
			$source = imagecreatefromjpeg($file);
			
			imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
			
			imagejpeg($thumb);
			imagejpeg($thumb,realpath("./img/arvores/thumbs")."/".md5($fileName.$newwidth.$newheight));
			imagejpeg($thumb,realpath("./img/arvores")."/thumb_".$fileName);
		}
	}
	
}
