<?PHP
function create_image($pic,$loc,$new_name,$new_w)
{
$im = imagecreatefromjpeg($pic);
$orwidth=imagesx($im); // get original width
$orheight=imagesy($im); //get original height

        if ($new_w > $orwidth) $toosmall = 1;

        if ($toosmall != 1) {

        $ratio = $orwidth/$orheight; // calc image ratio
        $new_h = round($new_w/$ratio,0); // calc new height keeping ratio of original
        $new_image=ImageCreateTrueColor($new_w,$new_h);
        imagecopyresized($new_image,$im,0,0,0,0,$new_w,$new_h,$orwidth,$orheight);
        imagejpeg($new_image,$loc.$new_name,100);
        imagedestroy($new_image);
        
        }

}

function create_thumb($pic,$loc,$new_name,$new_w)
{
$im = imagecreatefromjpeg($pic);
$orwidth=imagesx($im); // get original width
$orheight=imagesy($im); //get original height

        $ratio = $orwidth/$orheight; // calc image ratio
        $new_h = round($new_w/$ratio,0); // calc new height keeping ratio of original
        $new_image=ImageCreateTrueColor($new_w,$new_h);
        imagecopyresized($new_image,$im,0,0,0,0,$new_w,$new_h,$orwidth,$orheight);
        imagejpeg($new_image,$loc.$new_name,100);
        imagedestroy($new_image);

}

function deleteDir($dir)
{
   if (substr($dir, strlen($dir)-1, 1) != '/')
       $dir .= '/';

   //echo $dir;

   if ($handle = opendir($dir))
   {
       while ($obj = readdir($handle))
       {
           if ($obj != '.' && $obj != '..')
           {
               if (is_dir($dir.$obj))
               {
                   if (!deleteDir($dir.$obj))
                       return false;
               }
               elseif (is_file($dir.$obj))
               {
                   if (!unlink($dir.$obj))
                       return false;
               }
           }
       }

       closedir($handle);

       if (!@rmdir($dir))
           return false;
       return true;
   }
   return false;
}
?>
