Commit: 34700d925d52e09550e87c317d98f1ae6f9ffe42 Author: Levi Morrison <[email protected]> Mon, 21 Sep 2015 10:05:13 -0600 Parents: 77e279fcfe39e7a612a1e81131c0d5fe66ae21e9 Branches: master
Link: http://git.php.net/?p=web/php.git;a=commitdiff;h=34700d925d52e09550e87c317d98f1ae6f9ffe42 Log: Prefer SVG logo over PNG; serve .gz if possible Changed paths: M images/logo.php Diff: diff --git a/images/logo.php b/images/logo.php index 02a61fe..89c99d9 100644 --- a/images/logo.php +++ b/images/logo.php @@ -5,20 +5,52 @@ $refresh = isset($_GET["refresh"]) ? true : false; function imgheader($filename) { $ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); switch($ext) { - case "gif": - $hdr = "image/gif"; + case 'gif': + $hdr = 'image/gif'; break; - case "png": - $hdr = "image/png"; + case 'png': + $hdr = 'image/png'; break; - case "jpg": - case "jpeg": - $hdr = "image/jpeg"; + case 'jpg': + case 'jpeg': + $hdr = 'image/jpeg'; + break; + case 'svg': + $hdr = 'image/svg+xml'; break; default: return false; } - header("Content-Type: " . $hdr); + header("Content-Type: $hdr"); +} + + +function get_accepted_encodings() { + if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) { + $encodings = explode(',', $_SERVER['HTTP_ACCEPT_ENCODING']); + return array_map(function ($x) { + return trim($x); + }, $encodings); + } + return array(); +} + + +function serve_compressed_if_available($logo) { + $encodings = get_accepted_encodings(); + if (!empty($encodings)) { + foreach ($encodings as $encoding) { + if ($encoding === 'gzip') { + $encoded_file = "$logo.gz"; + if (file_exists($encoded_file)) { + header("Content-Encoding: $encoding"); + readfile($encoded_file); + return; + } + } + } + } + readfile($logo); } // Be 100% sure the timezone is set @@ -39,7 +71,7 @@ switch($_SERVER["QUERY_STRING"]) { break; default: $logos = array( - "./logos/[email protected]", + "./logos/php-logo.svg", ); } @@ -77,6 +109,6 @@ $tsstring = gmdate("D, d M Y H:i:s ", $now) . "GMT"; header("Last-Modified: " . $tsstring); header("Expires: " . date(DATE_RSS, $future)); imgheader($logo); -readfile($logo); +serve_compressed_if_available($logo); -- PHP Webmaster List Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
