<?php
	error_reporting(E_NONE);
	$config = parse_ini_file('preview_config.ini');
	$file = $_GET['file'];
	$icon = $_GET['icon'];
	if ($config['setting'] == '1') {
		if    (strtolower(substr($file,-4,4)) == '.png') { }
		elseif(strtolower(substr($file,-4,4)) == '.jpg') { }
		elseif(strtolower(substr($file,-4,4)) == '.gif') { }
		elseif(strtolower(substr($file,-5,5)) == '.jpeg'){ }
		else { disp_preset($icon); }
		$size = getimagesize($file) or disp_preset($icon);
		$w = $size[0];
		$h = $size[1];
		if ($h > 52 || $w > 52) {
			if ($h > $w) { 
				$nh = '52';
				$nw = ($w*$nh)/$h;
			} else {
				$nw = '52';
				$nh = ($h*$nw)/$w;
			}
		} else { $nw = $w; $nh = $h; }
		header('Content-Type: image/png');
		$image = imagecreatetruecolor($nw,$nh) or disp_preset($icon);
		$source = imagecreatefromstring(file_get_contents($file));
		imagecopyresized($image,$source,0,0,0,0,$nw,$nh,$w,$h);
		imagepng($image) or disp_preset($icon);
		imagedestroy($image) or disp_preset($icon);
	} else { disp_preset($icon); }
	function disp_preset($ico) {
		header('Location: '.$ico);die();
	}
?>