public function checkFile($file, array $config)
 {
     $driver = isset($config['imageDriversPriority']) ? image::getDriver(explode(" ", $config['imageDriversPriority'])) : "gd";
     $img = image::factory($driver, $file);
     if ($img->initError) {
         return "Unknown image format/encoding.";
     }
     return true;
 }
Beispiel #2
0
 protected function makeThumb($file, $overwrite = true)
 {
     $img = image::factory($this->imageDriver, $file);
     // Drop files which are not images
     if ($img->initError) {
         return true;
     }
     $fimg = new fastImage($file);
     $type = $fimg->getType();
     $fimg->close();
     if ($type === false) {
         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) && !@mkdir($thumbDir, $this->config['dirPerms'], true)) {
         return false;
     }
     if (!$overwrite && is_file($thumb)) {
         return true;
     }
     // Images with smaller resolutions than thumbnails
     if ($img->width <= $this->config['thumbWidth'] && $img->height <= $this->config['thumbHeight']) {
         // Drop only browsable types
         if (in_array($type, array("gif", "jpeg", "png"))) {
             return true;
         }
         // Resize image
     } elseif (!$img->resizeFit($this->config['thumbWidth'], $this->config['thumbHeight'])) {
         return false;
     }
     // Save thumbnail
     $options = array('file' => $thumb);
     if ($type == "gif") {
         $type = "jpeg";
     }
     if ($type == "jpeg") {
         $options['quality'] = $this->config['jpegQuality'];
     }
     return $img->output($type, $options);
 }
 protected function makeThumb($file, $overwrite = true)
 {
     $img = image::factory($this->imageDriver, $file);
     // Drop files which are not images
     if ($img->initError) {
         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) && !@mkdir($thumbDir, $this->config['dirPerms'], true)) {
         return false;
     }
     if (!$overwrite && is_file($thumb)) {
         return true;
     }
     // Images with smaller resolutions than thumbnails
     if ($img->width <= $this->config['thumbWidth'] && $img->height <= $this->config['thumbHeight']) {
         list($tmp, $tmp, $type) = @getimagesize($file);
         // Drop only browsable types
         if (in_array($type, array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
             return true;
         }
         // Resize image
     } elseif (!$img->resizeFit($this->config['thumbWidth'], $this->config['thumbHeight'])) {
         return false;
     }
     // Save thumbnail
     return $img->output("jpeg", array('file' => $thumb, 'quality' => $this->config['jpegQuality']));
 }
Beispiel #4
0
 protected function act_thumb()
 {
     $this->getDir($this->get['dir'], true);
     if (!isset($this->get['file']) || !isset($this->get['dir'])) {
         $this->sendDefaultThumb();
     }
     $file = $this->get['file'];
     if (basename($file) != $file) {
         $this->sendDefaultThumb();
     }
     $file = "{$this->thumbsDir}/{$this->type}/{$this->get['dir']}/{$file}";
     if (!is_file($file) || !is_readable($file)) {
         $file = "{$this->config['uploadDir']}/{$this->type}/{$this->get['dir']}/" . basename($file);
         if (!is_file($file) || !is_readable($file)) {
             $this->sendDefaultThumb($file);
         }
         $image = image::factory($this->imageDriver, $file);
         if ($image->initError) {
             $this->sendDefaultThumb($file);
         }
         list($tmp, $tmp, $type) = getimagesize($file);
         if (in_array($type, array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG)) && $image->width <= $this->config['thumbWidth'] && $image->height <= $this->config['thumbHeight']) {
             $mime = $type == IMAGETYPE_GIF ? "gif" : ($type == IMAGETYPE_PNG ? "png" : "jpeg");
             $mime = "image/{$mime}";
             httpCache::file($file, $mime);
         } else {
             $this->sendDefaultThumb($file);
         }
     }
     httpCache::file($file, "image/jpeg");
 }
Beispiel #5
0
 protected function act_thumb()
 {
     if (!isset($_GET['file']) || !isset($_GET['dir']) || !$this->checkFilename($_GET['file'])) {
         $this->sendDefaultThumb();
     }
     $dir = $this->getDir();
     $file = "{$this->thumbsTypeDir}/{$_GET['dir']}/{$_GET['file']}";
     // Create thumbnail
     if (!is_file($file) || !is_readable($file)) {
         $file = "{$dir}/{$_GET['file']}";
         if (!is_file($file) || !is_readable($file)) {
             $this->sendDefaultThumb($file);
         }
         $image = image::factory($this->imageDriver, $file);
         if ($image->initError) {
             $this->sendDefaultThumb($file);
         }
         $img = new fastImage($file);
         $type = $img->getType();
         $img->close();
         if (in_array($type, array("gif", "jpeg", "png")) && $image->width <= $this->config['thumbWidth'] && $image->height <= $this->config['thumbHeight']) {
             $mime = "image/{$type}";
             httpCache::file($file, $mime);
         } else {
             $this->sendDefaultThumb($file);
         }
         // Get type from already-existing thumbnail
     } else {
         $img = new fastImage($file);
         $type = $img->getType();
         $img->close();
     }
     httpCache::file($file, "image/{$type}");
 }