<?php
$imgName = "obraz1.jpg";
$tempDir = "./temp/";

if(isSet($_GET['width']) && isSet($_GET['height'])){
  $width = $_GET['width'];
  $height = $_GET['height'];

  if(!is_numeric($width) || !is_numeric($height) ||
     $width < 1 || $height < 1){
    die("error\nNieprawidłowe dane.");
  }

  if(!($img = imagecreatefromjpeg($imgName))){
    die("error\nBrak dostępu do obrazu.");
  }

  $sW = imagesx($img);
  $sH = imagesy($img);

  $tempImg = imagecreatetruecolor($width, $height);
  imagecopyresampled($tempImg, $img, 0, 0, 0, 0, $width, $height, $sW, $sH);

  $imgName = microtime().rand();
  imagejpeg($tempImg, $tempDir.$imgName);
  imagedestroy($tempImg);
  imagedestroy($img);
  echo $imgName;
}
else{
  if(!($img = imagecreatefromjpeg($imgName))){
    exit();
  }
  header('Content-Type: image/jpeg');
  imagejpeg($img);
  imagedestroy($img);
}
?>