<?php
// File source
$filename = $_GET['image']; 
$nwidth = $_GET['nwidth'];

if (file_exists($filename)) {

// Content type
header('Content-Type: image/jpeg');

// Dimensions
list($width, $height) = getimagesize($filename);
if ($width<80) {
$new_width = $width;
$new_height = $height;
}else{
$new_width = $nwidth;
$new_height = ($nwidth * $height)/$width;
}

// Resample
$imagethumb = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($imagethumb, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

// Output
imagejpeg($imagethumb, null, 100);
}?>