// check for cache file
 if (file_exists($cachepath)) {
     // time of cache
     $cachetime = filectime($cachepath);
     // file exists?
     if (file_exists($imagepath)) {
         $filetime = filectime($imagepath);
     } else {
         // image file not exists
         print 'Error: Imagefile does not exist - ' . $imagefile;
         exit;
     }
     // cache is newer? - show cache
     if ($cachetime > $filetime) {
         $thumb = new thumbnail($cachepath);
         $thumb->send($cachepath, $cachetime);
         exit;
     }
 }
 // check params
 if (!file_exists($imagepath)) {
     print 'Error: Imagefile does not exist - ' . $imagefile;
     exit;
 }
 if ($mode != 'w' and $mode != 'h' and $mode != 'a' and $mode != 'c') {
     print 'Error wrong mode - only h,w,a,c';
     exit;
 }
 if ($size == '') {
     print 'Error size is no INTEGER';
     exit;