array("50x50", "100x100", "120x120"), "Aperçu" =>array("500x500", "480x640", "640x480", "600x800", "800x600", "768x1024", "1024x768", "1024x1280", "1280x1024", "1200x1600", "1600x1200"), "Illustration" =>array("250x250") ); array_shift($pathinfo); // Type array_shift($pathinfo); // Size $picture=CONTENTS . "/".urldecode(implode("/", $pathinfo)); /*$AUTHENTICATED=FALSE; $LIMITED_ACCESS=!authorized(picture, FALSE); $AUTHENTICATED=$_SESSION[USERNAME]?TRUE:FALSE; if ($LIMITED_ACCESS) $cache_control="private"; else $cache_control="public";*/ $cache_control="private"; // One year cache require_once("Caching.php"); SendCacheHeaders(filemtime($picture), (3600 * 24 * 30 * 12), $cache_control); require_once("Authenticate.php"); if ( isset($LIMITED_ACCESS) &&( //----------- CHECK REFERRER // // http://www.hiegel.fr/~hugues/Aperçu/800x600/Photos/..." preg_replace( '%'. BASE_URL . "/(Aperçu|Miniature)/([[0-9]+x[0-9]+|Original)/Photos/" . '%', BASE_URL . "/Photos/", preg_replace( "%/[^/]*$%", "", urldecode("http" . ($_SERVER[HTTPS] == "on" ? "s" : "") . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'])) ) != // http://www.hiegel.fr/~hugues/Photos/..." preg_replace( "%/[^/]*$%", "", urldecode($_SERVER['HTTP_REFERER']) ) ) ) { if (! http_authenticate($picture)) exit; } switch($Type) { case "Aperçu": if (in_array($Size, $allowed_ratios["Aperçu"])) { $Width= substr($Size, 0, strpos($Size, "x")); $Height=substr($Size, strpos($Size, "x") + 1); } else if (strcmp($Size, "Original")) die ("$pathinfo[0] : \"$Size\" is not an available size !!"); $FileType="jpg"; $Miniaturized=0; break; default: case "Miniature": if (in_array($Size, $allowed_ratios["Miniature"])) { $Width= substr($Size, 0, strpos($Size, "x")); $Height=substr($Size, strpos($Size, "x") + 1); } else { $Width=100; $Height=100; } $Miniaturized=1; $FileType="png"; break; } $width=@$Width; $height=@$Height; //if (filesize($picture) > 3*1024*1024) exit; $mimetype=mime_content_type($picture); if ( !strcmp($mimetype, "image/gif") ||!strcmp($mimetype, "image/mng")) { $FileType="gif"; } // The md5() is to obtain a relative long complex filename // The fileinode() is to obtain *exactly* the picture we want to point to // so we can give back a generated thumbnail even if it has been moved on // another folder in the filesystem. // The third test is made to force re-generation of thumbnails if this // script has been modified. :-) $size=GetImageSize($picture); if ( !strcmp($Size, "Original") ||(!strcmp("Aperçu", $pathinfo[0]) && ($size[0] < $width) && ($size[1] < $height)) ) { $thumbnail=$picture; } else { $thumbnail="/var/cache/www/Miniatures/".$width."x".$height."/".md5(fileinode($picture)).".$FileType"; if ( !is_dir(dirname($thumbnail))) @mkdir(dirname($thumbnail)); if ( !file_exists($thumbnail) || filemtime($thumbnail) < filemtime($picture) || filemtime($thumbnail) < filemtime($_SERVER['SCRIPT_FILENAME']) ) { // Keep aspect ratio if ( (!$width && !$height) ||(($size[0] < $width) && ($size[1] < $height)) ) { $width = $size[0]; $height = $size[1]; } else { if ($size[0] / $size[1] > $width / $height) $height = floor($width * $size[1] / $size[0]); else $width = floor($height * $size[0] / $size[1]); } // system("mkdir -p `dirname $thumbnail`"); // ImageMagick is most powerful and knows most image formats than PHP... $command = "convert 2>&1 " . "\"$picture\"" .($Miniaturized ? " -geometry '".$Width."x".$Height."^'" ." -gravity center" ." -extent '".$Width."x".$Height."'" : " -geometry ".$width."x".$height ) ." $thumbnail"; system($command); } } if (file_exists($thumbnail)) { header("Content-Type: " . mime_content_type($thumbnail));// or die(""); SendCacheHeaders(filemtime($picture), (3600 * 24 * 30 * 12), $cache_control); echo file_get_contents($thumbnail); } else die ("$pathinfo[0] : Error while reading $picture"); ?>