<?php
//Preview File, generates a JPG file.
$share_id = rawurldecode(stripslashes($_GET['share']));
$path = rawurldecode(stripslashes($_GET['preview']));


if ($_GET['type'] == 2){
	$w = 94;
	$h = 94;
} else {
	$w = 170;
	$h = 170;
}


//find share... that has permissions
$share = afbGetShare($share_id);
if ($share && isset($share['id']) && $share['perm_list']){
	$fullpath = $share['dir'].trim($path,'/');
	//check file..
	if (CheckFile($share['dir'],$fullpath,true)) {
		//include image manipulation file.
		require_once('_includes/class.snapshot.php');
		
		$myimage = new ImageSnapshot;		
		$myimage->ImageFile = $fullpath;
		$myimage->Width = $w;
		$myimage->Height =  $h;
		$myimage->Resize = true; //if false, snapshot takes a portion from the unsized image.
		$myimage->ResizeScale = 100;
		$myimage->Position = 'center';
		$myimage->Compression = 80;
		
		//getting img into var
		if ($myimage->ProcessImage() !== false) {
			header("Content-type: image/jpg"); // act as a jpg file to browser 
			echo $myimage->GetImageContents();
			exit();
		}
	}
}
//return clear image
header("Content-type: image/jpg"); // act as a jpg file to browser 
echo readfile_chunked('_includes/clear.gif');
exit();
?>