- $urlhash = 'pic:' . sha1($_REQUEST['url']);
- // Double encoded url - happens with Diaspora
- $urlhash2 = 'pic:' . sha1(urldecode($_REQUEST['url']));
-
- $cachefile = get_cachefile(hash("md5", $_REQUEST['url']));
- if ($cachefile != '') {
- if (file_exists($cachefile)) {
- $img_str = file_get_contents($cachefile);
-
- $mime = image_type_to_mime_type(exif_imagetype($cachefile));
-
- header("Content-type: $mime");
- header("Last-Modified: " . gmdate("D, d M Y H:i:s", time()) . " GMT");
- header('Etag: "'.md5($img_str).'"');
- header("Expires: " . gmdate("D, d M Y H:i:s", time() + (31536000)) . " GMT");
- header("Cache-Control: max-age=31536000");
-
- echo $img_str;
-
- //if ($a->config["system"]["db_log"] != "") {
- // $stamp2 = microtime(true);
- // $duration = round($stamp2-$stamp1, 3);
- // if ($duration > $a->config["system"]["db_loglimit"])
- // @file_put_contents($a->config["system"]["db_log"], $duration."\t".strlen($img_str)."\t".$_REQUEST['url']."\n", FILE_APPEND);
- //}
-
- killme();
+ if (!$direct_cache) {
+ $urlhash = 'pic:' . sha1($_REQUEST['url']);
+ // Double encoded url - happens with Diaspora
+ $urlhash2 = 'pic:' . sha1(urldecode($_REQUEST['url']));
+
+ $cachefile = get_cachefile(hash("md5", $_REQUEST['url']));
+ if ($cachefile != '') {
+ if (file_exists($cachefile)) {
+ $img_str = file_get_contents($cachefile);
+ $mime = image_type_to_mime_type(exif_imagetype($cachefile));
+
+ header("Content-type: $mime");
+ header("Last-Modified: " . gmdate("D, d M Y H:i:s", time()) . " GMT");
+ header('Etag: "'.md5($img_str).'"');
+ header("Expires: " . gmdate("D, d M Y H:i:s", time() + (31536000)) . " GMT");
+ header("Cache-Control: max-age=31536000");
+
+ // reduce quality - if it isn't a GIF
+ if ($mime != "image/gif") {
+ $img = new Photo($img_str, $mime);
+ if($img->is_valid()) {
+ $img_str = $img->imageString();
+ }
+ }
+
+ echo $img_str;
+ killme();
+ }