<?php
/* PROJECT INFO --------------------------------------------------------------------------------------------------------
Version: 1.5.2
Changelog: http://adaptive-images.com/changelog.txt
Homepage: http://adaptive-images.com
GitHub: https://github.com/MattWilcox/Adaptive-Images
Twitter: @responsiveimg
LEGAL:
Adaptive Images by Matt Wilcox is licensed under a Creative Commons Attribution 3.0 Unported License.
/* CONFIG ----------------------------------------------------------------------------------------------------------- */
$resolutions = array(1600, 1400, 1200, 768, 480); // the resolution break-points to use (screen widths, in pixels)
$cache_path = "ai-cache"; // where to store the generated re-sized images. Specify from your document root!
$jpg_quality = 75; // the quality of any generated JPGs on a scale of 0 to 100
$sharpen = TRUE; // Shrinking images can blur details, perform a sharpen on re-scaled images?
$watch_cache = TRUE; // check that the adapted image isn't stale (ensures updated source images are re-cached)
$browser_cache = 60*60*24*7; // How long the BROWSER cache should last (seconds, minutes, hours, days. 7days by default)
/* END CONFIG ----------------------------------------------------------------------------------------------------------
------------------------ Don't edit anything after this line unless you know what you're doing -------------------------
--------------------------------------------------------------------------------------------------------------------- */
/* get all of the required data from the HTTP request */
$document_root = $_SERVER['DOCUMENT_ROOT'];
$requested_uri = parse_url(urldecode($_SERVER['REQUEST_URI']), PHP_URL_PATH);
$requested_file = basename($requested_uri);
$source_file = $document_root.$requested_uri;
$resolution = FALSE;
/* Mobile detection
NOTE: only used in the event a cookie isn't available. */
function is_mobile() {
$userAgent = strtolower($_SERVER['HTTP_USER_AGENT']);
return strpos($userAgent, 'mobile');
}
/* Does the UA string indicate this is a mobile? */
if(!is_mobile()){
$is_mobile = FALSE;
} else {
$is_mobile = TRUE;
}
// does the $cache_path directory exist already?
if (!is_dir("$document_root/$cache_path")) { // no
if (!mkdir("$document_root/$cache_path", 0755, true)) { // so make it
if (!is_dir("$document_root/$cache_path")) { // check again to protect against race conditions
// uh-oh, failed to make that directory
sendErrorImage("Failed to create cache directory at: $document_root/$cache_path");
}
}
}
/* helper function: Send headers and returns an image. */
function sendImage($filename, $browser_cache) {
$extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
if (in_array($extension, array('png', 'gif', 'jpeg'))) {
header("Content-Type: image/".$extension);
} else {
header("Content-Type: image/jpeg");
}
header("Cache-Control: private, max-age=".$browser_cache);
header('Expires: '.gmdate('D, d M Y H:i:s', time()+$browser_cache).' GMT');
header('Content-Length: '.filesize($filename));
readfile($filename);
exit();
}
/* helper function: Create and send an image with an error message. */
function sendErrorImage($message) {
/* get all of the required data from the HTTP request */
$document_root = $_SERVER['DOCUMENT_ROOT'];
$requested_uri = parse_url(urldecode($_SERVER['REQUEST_URI']), PHP_URL_PATH);
$requested_file = basename($requested_uri);
$source_file = $document_root.$requested_uri;
if(!is_mobile()){
$is_mobile = "FALSE";
} else {
$is_mobile = "TRUE";
}
$im = ImageCreateTrueColor(800, 300);
$text_color = ImageColorAllocate($im, 233, 14, 91);
$message_color = ImageColorAllocate($im, 91, 112, 233);
ImageString($im, 5, 5, 5, "Adaptive Images encountered a problem:", $text_color);
ImageString($im, 3, 5, 25, $message, $message_color);
ImageString($im, 5, 5, 85, "Potentially useful information:", $text_color);
ImageString($im, 3, 5, 105, "DOCUMENT ROOT IS: $document_root", $text_color);
ImageString($im, 3, 5, 125, "REQUESTED URI WAS: $requested_uri", $text_color);
ImageString($im, 3, 5, 145, "REQUESTED FILE WAS: $requested_file", $text_color);
ImageString($im, 3, 5, 165, "SOURCE FILE IS: $source_file", $text_color);
ImageString($im, 3, 5, 185, "DEVICE IS MOBILE? $is_mobile", $text_color);
header("Cache-Control: no-store");
header('Expires: '.gmdate('D, d M Y H:i:s', time()-1000).' GMT');
header('Content-Type: image/jpeg');
ImageJpeg($im);
ImageDestroy($im);
exit();
}
/* sharpen images function */
function findSharp($intOrig, $intFinal) {
$intFinal = $intFinal * (750.0 / $intOrig);
$intA = 52;
$intB = -0.27810650887573124;
$intC = .00047337278106508946;
$intRes = $intA + $intB * $intFinal + $intC * $intFinal * $intFinal;
return max(round($intRes), 0);
}
/* refreshes the cached image if it's outdated */
function refreshCache($source_file, $cache_file, $resolution) {
if (file_exists($cache_file)) {
// not modified
if (filemtime($cache_file) >= filemtime($source_file)) {
return $cache_file;
}
// modified, clear it
unlink($cache_file);
}
return generateImage($source_file, $cache_file, $resolution);
}
/* generates the given cache file for the given source file with the given resolution */
function generateImage($source_file, $cache_file, $resolution) {
global $sharpen, $jpg_quality;
$extension = strtolower(pathinfo($source_file, PATHINFO_EXTENSION));
// Check the image dimensions
$dimensions = GetImageSize($source_file);
$width = $dimensions[0];
$height = $dimensions[1];
// Do we need to downscale the image?
if ($width <= $resolution) { // no, because the width of the source image is already less than the client width
return $source_file;
}
// We need to resize the source image to the width of the resolution breakpoint we're working with
$ratio = $height/$width;
$new_width = $resolution;
$new_height = ceil($new_width * $ratio);
$dst = ImageCreateTrueColor($new_width, $new_height); // re-sized image
switch ($extension) {
case 'png':
$src = @ImageCreateFromPng($source_file); // original image
break;
case 'gif':
$src = @ImageCreateFromGif($source_file); // original image
break;
default:
$src = @ImageCreateFromJpeg($source_file); // original image
ImageInterlace($dst, true); // Enable interlancing (progressive JPG, smaller size file)
break;
}
if($extension=='png'){
imagealphablending($dst, false);
imagesavealpha($dst,true);
$transparent = imagecolorallocatealpha($dst, 255, 255, 255, 127);
imagefilledrectangle($dst, 0, 0, $new_width, $new_height, $transparent);
}
ImageCopyResampled($dst, $src, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // do the resize in memory
ImageDestroy($src);
// sharpen the image?
// NOTE: requires PHP compiled with the bundled version of GD (see http://php.net/manual/en/function.imageconvolution.php)
if($sharpen == TRUE && function_exists('imageconvolution')) {
$intSharpness = findSharp($width, $new_width);
$arrMatrix = array(
array(-1, -2, -1),
array(-2, $intSharpness + 12, -2),
array(-1, -2, -1)
);
imageconvolution($dst, $arrMatrix, $intSharpness, 0);
}
$cache_dir = dirname($cache_file);
// does the directory exist already?
if (!is_dir($cache_dir)) {
if (!mkdir($cache_dir, 0755, true)) {
// check again if it really doesn't exist to protect against race conditions
if (!is_dir($cache_dir)) {
// uh-oh, failed to make that directory
ImageDestroy($dst);
sendErrorImage("Failed to create cache directory: $cache_dir");
}
}
}
if (!is_writable($cache_dir)) {
sendErrorImage("The cache directory is not writable: $cache_dir");
}
// s
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
黑色个性的图片个人博客模板_黑色个性html5个人博客.rar (83个子文件)
02.jpg 482KB
Banda_regular-webfont.woff 38KB
OpenSans-ExtraBoldItalic-webfont.woff 15KB
sofia-regular-webfont.ttf 67KB
font-face.css 7KB
OpenSans-ExtraBold-webfont.eot 21KB
adaptive-images.php 12KB
hot-pink.css 2KB
main.css 15KB
Matchbook-webfont.ttf 23KB
OpenSans-Semibold-webfont.ttf 20KB
OpenSans-BoldItalic-webfont.woff 15KB
Banda_regular-webfont.ttf 101KB
OpenSans-LightItalic-webfont.svg 27KB
OpenSans-BoldItalic-webfont.eot 23KB
OpenSans-Regular-webfont.svg 25KB
brillant-dark.png 3KB
OpenSans-ExtraBold-webfont.svg 25KB
OpenSans-Light-webfont.eot 20KB
gallery-hex.html 6KB
01.jpg 334KB
OpenSans-Semibold-webfont.woff 14KB
fontawesome-webfont.eot 38KB
OpenSans-LightItalic-webfont.woff 16KB
OpenSans-ExtraBoldItalic-webfont.ttf 22KB
OpenSans-ExtraBold-webfont.ttf 20KB
sofia-regular-webfont.eot 31KB
OpenSans-SemiboldItalic-webfont.ttf 23KB
OpenSans-LightItalic-webfont.ttf 23KB
image.jpg 3.59MB
OpenSans-ExtraBold-webfont.woff 14KB
main.js 2KB
post.html 8KB
font-awesome.css 14KB
brillant.png 85B
normalize.css 9KB
juicy-orange.css 5KB
OpenSans-SemiboldItalic-webfont.svg 27KB
Matchbook-webfont.woff 13KB
OpenSans-Italic-webfont.svg 27KB
fontawesome-webfont.woff 41KB
OpenSans-SemiboldItalic-webfont.eot 23KB
Matchbook-webfont.eot 23KB
categories.html 5KB
OpenSans-Light-webfont.svg 24KB
ocean-blue.css 2KB
OpenSans-Bold-webfont.svg 25KB
OpenSans-Regular-webfont.eot 20KB
OpenSans-Bold-webfont.woff 14KB
404.html 5KB
OpenSans-ExtraBoldItalic-webfont.eot 23KB
Banda_regular-webfont.eot 37KB
OpenSans-Italic-webfont.ttf 23KB
OpenSans-ExtraBoldItalic-webfont.svg 26KB
OpenSans-Semibold-webfont.svg 25KB
jquery-1.8.0.min.js 90KB
OpenSans-LightItalic-webfont.eot 24KB
OpenSans-Light-webfont.ttf 20KB
typography.css 5KB
index.html 8KB
single-image.html 4KB
OpenSans-SemiboldItalic-webfont.woff 15KB
OpenSans-Bold-webfont.eot 21KB
fontawesome-webfont.svg 127KB
Matchbook-webfont.svg 33KB
Banda_regular.otf 65KB
OpenSans-Semibold-webfont.eot 21KB
OpenSans-BoldItalic-webfont.ttf 23KB
fontawesome-webfont.ttf 67KB
sofia-regular-webfont.svg 112KB
Banda_regular-webfont.svg 94KB
OpenSans-Regular-webfont.woff 14KB
OpenSans-Regular-webfont.ttf 20KB
OpenSans-Bold-webfont.ttf 21KB
OpenSans-BoldItalic-webfont.svg 26KB
OpenSans-Italic-webfont.eot 23KB
OpenSans-Light-webfont.woff 14KB
03.jpg 224KB
OpenSans-Italic-webfont.woff 15KB
placeholder.jpg 27KB
plugins.js 12KB
sofia-regular-webfont.woff 36KB
gallery.html 5KB
共 83 条
- 1
资源评论
Q_97095639
- 粉丝: 377
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功