<?php
  
function image_shrink_size($file_in$max_x 0$max_y 0
    {
      list(
$width$height) = getimagesize($file_in);
      if (!
$width || !$height) {
          return array(
00);
      }
      if (
$max_x && $width $max_x) {
          
$height round($height $max_x $width);
          
$width $max_x;
      }
      if (
$max_y && $height $max_y) {
          
$width round($width $max_y $height);
          
$height $max_y;
      }
      return array(
$width$height);
    }
                                            
  function 
image_resize($file_in$file_out$width$height
    {
      
$imagesize getimagesize($file_in);
      if ((!
$width && !$height) || !$imagesize[0] || !$imagesize[1]) {
          return 
false;
      }
      if (
$imagesize[0] == $width && $imagesize[1] == $height) {
          return 
copy($file_in$file_out);
      }
      switch (
$imagesize[2]) {
          case 
1$img imagecreatefromgif($file_in); break;
          case 
2$img imagecreatefromjpeg($file_in); break;
          case 
3$img imagecreatefrompng($file_in); break;
          default: return 
false;
      }
      if (!
$img) {
          return 
false;
      }
      
$img2 imagecreatetruecolor($width$height);
      
imagecopyresampled($img2$img0000$width$height$imagesize[0], $imagesize[1]);
      if (
$imagesize[2] == 2) {
          return 
imagejpeg($img2$file_out);
      } elseif (
$imagesize[2] == && function_exists("imagegif")) {
          
imagetruecolortopalette($img2false256);
          return 
imagegif($img2$file_out);
      } else {
          return 
imagepng($img2$file_out);
      }
    }
    
    
    
// $soubor - vstupni obrazek
    // $cil - vystupni soubor s cestou vcetna nazvu
    // $width - vystupni sirka
    // $height - vystupni vyska 
    
    
image_resize($soubor$ulozit_kam$width$height);
?>