<?php

  function print_thumb($src, $desired_width = 80){

    if( !file_exists($src) )
      return false;

    /* read the source image */
    $source_image = imagecreatefromjpeg($src);
    $width = imagesx($source_image);
    $height = imagesy($source_image);

    /* find the "desired height" of this thumbnail, relative to the desired width  */
    $desired_height = floor($height * ($desired_width / $width));

    /* create a new, "virtual" image */
    $virtual_image = imagecreatetruecolor($desired_width, $desired_height);

    /* copy source image at a resized size */
    imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);


    // Set the content type header - in this case image/jpeg
    header('Content-Type: image/jpeg');

    // Output the image
    imagejpeg($virtual_image);

    return true;

  }

  if( isset( $_GET['file'] ) && !empty( $_GET['file'] ) ){

    if( !print_thumb( $_GET['file'] ) ){

      echo 'Failed to create thumb for "'.$_GET['file'].'"';

    }else{

      // The Thumb would have been returned

    }

  }else{

    echo 'No File specified';

  }
?>