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

if(isSet($_GET['proc'])){
  $proc = $_GET['proc'];

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

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

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

  $width = $sW * $proc / 100;
  $height = $sH * $proc / 100;

  $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);
}
?>