Beispiel #1
0
 function generateThumbnail($saveAs, $options)
 {
     $destination = WWW_ROOT . $options['directory'] . DS . basename($saveAs);
     $ext = substr(basename($saveAs), strrpos(basename($saveAs), '.') + 1);
     if ($ext == '.jpg' || $ext == '.jpeg') {
         $format = 'jpeg';
     } elseif ($ext == 'png') {
         $format = 'png';
     } elseif ($ext == 'gif') {
         $format = 'gif';
     } else {
         $format = 'jpeg';
     }
     $phpThumb = new phpthumb();
     $phpThumb->setSourceFilename($saveAs);
     $phpThumb->setCacheDirectory(CACHE);
     $phpThumb->setParameter('w', $options['width']);
     if (!empty($option['height'])) {
         $phpThumb->setParameter('h', $options['height']);
     }
     $phpThumb->setParameter('f', $format);
     if (!empty($options['phpThumb'])) {
         foreach ($options['phpThumb'] as $name => $value) {
             if (!empty($value)) {
                 $phpThumb->setParameter($name, $value);
             }
         }
     }
     if ($phpThumb->generateThumbnail()) {
         if ($phpThumb->RenderToFile($destination)) {
             chmod($destination, 0644);
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }