Exemplo n.º 1
0
 protected function makeThumb($file, $overwrite = true)
 {
     $gd = new gd($file);
     // Drop files which are not GD handled images
     if ($gd->init_error) {
         return true;
     }
     $thumb = substr($file, strlen($this->config['uploadDir']));
     $thumb = $this->config['uploadDir'] . "/" . $this->config['thumbsDir'] . "/" . $thumb;
     $thumb = path::normalize($thumb);
     $thumbDir = dirname($thumb);
     if (!is_dir($thumbDir) && !dir::rmkdir($thumbDir, $this->config['dirPerms'])) {
         return false;
     }
     if (!$overwrite && is_file($thumb)) {
         return true;
     }
     // Images with smaller resolutions than thumbnails
     if ($gd->get_width() <= $this->config['thumbWidth'] && $gd->get_height() <= $this->config['thumbHeight']) {
         $browsable = array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_JPEG2000, IMAGETYPE_PNG);
         // Drop only browsable types
         if (in_array($gd->type, $browsable)) {
             return true;
         }
         // Resize image
     } elseif (!$gd->resize_fit($this->config['thumbWidth'], $this->config['thumbHeight'])) {
         return false;
     }
     // Save thumbnail
     return $gd->imagejpeg($thumb, $this->config['jpegQuality']);
 }