<?php

$urlmail=@$_REQUEST['image'];
$urlmail2=basename(@$_REQUEST['image']);
$image=explode(".",$urlmail2);


if(isset($_REQUEST['rwd']))
	$rwd=@$_REQUEST['rwd'];
if(isset($_POST['rwd']))
	$rwd=@$_POST['rwd'];
if(isset($_GET['rwd']))
	$rwd=@$_GET['rwd'];
if($rwd=='')
	$rwd=120;

if(isset($_REQUEST['rht']))
	$rht=@$_REQUEST['rht'];
if(isset($_POST['rht']))
	$rht=@$_POST['rht'];
if(isset($_GET['rht']))
	$rht=@$_GET['rht'];
if($rht=='')
	$rht=120;


//validation
if($image[1]=='jpg' )
{ 
	$mainimage=imagecreatefromjpeg($urlmail);
	$mainwidth=imagesx($mainimage);
	$mainheigth=imagesy($mainimage);

	$thumbwidth=$rwd;
	$thumbheight=$rht;

	$mythumbnail=imagecreatetruecolor($thumbwidth, $thumbheight);

	imagecopyresampled($mythumbnail, $mainimage, 0, 0,0,0, $thumbwidth, $thumbheight, $mainwidth, $mainheigth);

	header("Content-type: image/jpeg");
	imagejpeg($mythumbnail);
}
else if($image[1]=='gif' || $image[1]=='jpeg' ) //$url=$urlmail;
{
	$mainimage=imagecreatefromgif($urlmail);
	$mainwidth=imagesx($mainimage);
	$mainheigth=imagesy($mainimage);

	$thumbwidth=$rwd;
	$thumbheight=$rht;

	$mythumbnail=imagecreatetruecolor($thumbwidth, $thumbheight);

	imagecopyresampled($mythumbnail, $mainimage, 0, 0,0,0, $thumbwidth, $thumbheight, $mainwidth, $mainheigth);

	header("Content-type: image/jpeg");
	imagejpeg($mythumbnail);
}
elseif($image[1]=='png')
{
	$mainimage=imagecreatefrompng($urlmail);
	$mainwidth=imagesx($mainimage);
	$mainheigth=imagesy($mainimage);

	$thumbwidth=$rwd;
	$thumbheight=$rht;

	$mythumbnail=imagecreatetruecolor($thumbwidth, $thumbheight);

	imagecopyresampled($mythumbnail, $mainimage, 0, 0,0,0, $thumbwidth, $thumbheight, $mainwidth, $mainheigth);

	header("Content-type: image/jpeg");
	imagejpeg($mythumbnail);
}
else
{
	$urlmail="./images/img_na.gif";
	$mainimage=imagecreatefrompng($urlmail);
	$mainwidth=imagesx($mainimage);
	$mainheigth=imagesy($mainimage);

	$thumbwidth=$rwd;
	$thumbheight=$rht;

	$mythumbnail=imagecreatetruecolor($thumbwidth, $thumbheight);

	imagecopyresampled($mythumbnail, $mainimage, 0, 0,0,0, $thumbwidth, $thumbheight, $mainwidth, $mainheigth);

	header("Content-type: image/jpeg");
	imagejpeg($mythumbnail);
}

?>


	

