Example #1
0
 public function test_makeThumb_PDF()
 {
     $img = new \libraries\Image(FCPATH . "/data/tests/simple.pdf");
     $img->makeThumb(150, 150);
     $thumb = $img->get(IMAGETYPE_JPEG);
     $this->t->ok($thumb !== "", "Got thumbnail");
 }
Example #2
0
 function thumbnail()
 {
     $id = $this->uri->segment(3);
     if (!$this->mfile->valid_id($id)) {
         return $this->_non_existent();
     }
     $etag = "{$id}-thumb";
     handle_etag($etag);
     $thumb_size = 150;
     $cache_timeout = 60 * 60 * 24 * 30;
     # 1 month
     $filedata = $this->mfile->get_filedata($id);
     if (!$filedata) {
         throw new \exceptions\ApiException("file/thumbnail/filedata-unavailable", "Failed to get file data");
     }
     $cache_key = $filedata['data_id'] . '_thumb_' . $thumb_size;
     $thumb = cache_function($cache_key, $cache_timeout, function () use($filedata, $thumb_size) {
         $CI =& get_instance();
         $img = new libraries\Image($this->mfile->file($filedata["data_id"]));
         $img->makeThumb($thumb_size, $thumb_size);
         $thumb = $img->get(IMAGETYPE_JPEG);
         return $thumb;
     });
     $this->output->set_header("Cache-Control:max-age=31536000, public");
     $this->output->set_header("Expires: " . date("r", time() + 365 * 24 * 60 * 60));
     $this->output->set_content_type("image/jpeg");
     $this->output->set_output($thumb);
 }