/** * Provide an image to the user, if he is allowed to * see it. If $thumb is true, provide the thumb associated * to the image. * * @param string $file * @param string $thumb * @return void * @author Thibaud Rohmer */ public static function Image($file, $thumb = false, $large = false, $output = true, $dl = false) { if (!Judge::view($file)) { return; } if (function_exists("error_reporting")) { error_reporting(0); } /// Check item $file_type = File::Type($file); switch ($file_type) { case "Image": $is_video = false; break; case "Video": $is_video = true; break; default: return; } //error_log('DEBUG/Provider::image: '.$file.' '.($is_video?'is_video':'')); if (!$large) { try { if ($is_video) { //TODO: fix so when opening the folder the first time no need to do F5 to see //the freshly created thumbnail Video::FastEncodeVideo($file); $basefile = new File($file); $basepath = File::a2r($file); $path = Settings::$thumbs_dir . dirname($basepath) . "/" . $basefile->name . ".jpg"; } elseif ($thumb) { // Img called on a video, return the thumbnail $path = Provider::thumb($file); } else { $path = Provider::small($file); } } catch (Exception $e) { // do nothing } } if (!isset($path) || !file_exists($path)) { error_log('ERROR/Provider::image path:' . $path . ' does not exist, using ' . $file); $path = $file; } if ($output) { if ($dl) { header('Content-Disposition: attachment; filename="' . basename($file) . '"'); } else { $expires = 60 * 60 * 24 * 14; $last_modified_time = filemtime($path); $last_modified_time = 0; $etag = md5_file($file); header("Last-Modified: " . 0 . " GMT"); header("Pragma: public"); header("Cache-Control: max-age=360000"); header("Etag: {$etag}"); header("Cache-Control: maxage=" . $expires); header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT'); } header('Content-type: image/jpeg'); if (File::Type($path) == "Image") { readfile($path); return; try { imagejpeg(Provider::autorotate_jpeg($path)); } catch (Exception $e) { error_log('ERROR/Provider.php: cannot rotate ' . $path . ': ' . $e); readfile($path); } } else { readfile($path); } } }
/** * Return image(s) $img */ public static function get_img($key, $img, $t = 'large') { if (is_array($img)) { $res = array(); foreach ($img as $i) { $p = get_img($key, $i, $t); if (isset($p)) { $res[] = $p; } } return $res; } else { $i = File::r2a($img); if (Judge::view($i)) { switch ($t) { case "thumb": return file_get_contents(Provider::thumb($i)); case "small": return file_get_contents(Provider::small($i)); case "large": default: return file_get_contents($i); } } } }