├── .DS_Store ├── .htaccess ├── adaptive-images.php ├── ai-cookie.php ├── changelog.txt ├── instructions.htm ├── instructions_de.htm ├── instructions_tr.htm └── readme.textile /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MattWilcox/Adaptive-Images/3cc26652a9be51e2c5fad36e4dc889b65ee45a36/.DS_Store -------------------------------------------------------------------------------- /.htaccess: -------------------------------------------------------------------------------- 1 | 2 | Options +FollowSymlinks 3 | RewriteEngine On 4 | 5 | # Adaptive-Images ----------------------------------------------------------------------------------- 6 | 7 | # Add any directories you wish to omit from the Adaptive-Images process on a new line, as follows: 8 | # RewriteCond %{REQUEST_URI} !ignore-this-directory 9 | # RewriteCond %{REQUEST_URI} !and-ignore-this-directory-too 10 | 11 | RewriteCond %{REQUEST_URI} !assets 12 | 13 | # don't apply the AI behaviour to images inside AI's cache folder: 14 | RewriteCond %{REQUEST_URI} !ai-cache 15 | 16 | # Send any GIF, JPG, or PNG request that IS NOT stored inside one of the above directories 17 | # to adaptive-images.php so we can select appropriately sized versions 18 | 19 | RewriteRule \.(?:jpe?g|gif|png)$ adaptive-images.php 20 | 21 | # END Adaptive-Images ------------------------------------------------------------------------------- 22 | -------------------------------------------------------------------------------- /adaptive-images.php: -------------------------------------------------------------------------------- 1 | = filemtime($source_file)) { 123 | return $cache_file; 124 | } 125 | 126 | // modified, clear it 127 | unlink($cache_file); 128 | } 129 | return generateImage($source_file, $cache_file, $resolution); 130 | } 131 | 132 | /* generates the given cache file for the given source file with the given resolution */ 133 | function generateImage($source_file, $cache_file, $resolution) { 134 | global $sharpen, $jpg_quality; 135 | 136 | $extension = strtolower(pathinfo($source_file, PATHINFO_EXTENSION)); 137 | 138 | // Check the image dimensions 139 | $dimensions = GetImageSize($source_file); 140 | $width = $dimensions[0]; 141 | $height = $dimensions[1]; 142 | 143 | // Do we need to downscale the image? 144 | if ($width <= $resolution) { // no, because the width of the source image is already less than the client width 145 | return $source_file; 146 | } 147 | 148 | // We need to resize the source image to the width of the resolution breakpoint we're working with 149 | $ratio = $height/$width; 150 | $new_width = $resolution; 151 | $new_height = ceil($new_width * $ratio); 152 | $dst = ImageCreateTrueColor($new_width, $new_height); // re-sized image 153 | 154 | switch ($extension) { 155 | case 'png': 156 | $src = @ImageCreateFromPng($source_file); // original image 157 | break; 158 | case 'gif': 159 | $src = @ImageCreateFromGif($source_file); // original image 160 | break; 161 | default: 162 | $src = @ImageCreateFromJpeg($source_file); // original image 163 | ImageInterlace($dst, true); // Enable interlancing (progressive JPG, smaller size file) 164 | break; 165 | } 166 | 167 | if($extension=='png'){ 168 | imagealphablending($dst, false); 169 | imagesavealpha($dst,true); 170 | $transparent = imagecolorallocatealpha($dst, 255, 255, 255, 127); 171 | imagefilledrectangle($dst, 0, 0, $new_width, $new_height, $transparent); 172 | } 173 | 174 | ImageCopyResampled($dst, $src, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // do the resize in memory 175 | ImageDestroy($src); 176 | 177 | // sharpen the image? 178 | // NOTE: requires PHP compiled with the bundled version of GD (see http://php.net/manual/en/function.imageconvolution.php) 179 | if($sharpen == TRUE && function_exists('imageconvolution')) { 180 | $intSharpness = findSharp($width, $new_width); 181 | $arrMatrix = array( 182 | array(-1, -2, -1), 183 | array(-2, $intSharpness + 12, -2), 184 | array(-1, -2, -1) 185 | ); 186 | imageconvolution($dst, $arrMatrix, $intSharpness, 0); 187 | } 188 | 189 | $cache_dir = dirname($cache_file); 190 | 191 | // does the directory exist already? 192 | if (!is_dir($cache_dir)) { 193 | if (!mkdir($cache_dir, 0755, true)) { 194 | // check again if it really doesn't exist to protect against race conditions 195 | if (!is_dir($cache_dir)) { 196 | // uh-oh, failed to make that directory 197 | ImageDestroy($dst); 198 | sendErrorImage("Failed to create cache directory: $cache_dir"); 199 | } 200 | } 201 | } 202 | 203 | if (!is_writable($cache_dir)) { 204 | sendErrorImage("The cache directory is not writable: $cache_dir"); 205 | } 206 | 207 | // save the new file in the appropriate path, and send a version to the browser 208 | switch ($extension) { 209 | case 'png': 210 | $gotSaved = ImagePng($dst, $cache_file); 211 | break; 212 | case 'gif': 213 | $gotSaved = ImageGif($dst, $cache_file); 214 | break; 215 | default: 216 | $gotSaved = ImageJpeg($dst, $cache_file, $jpg_quality); 217 | break; 218 | } 219 | ImageDestroy($dst); 220 | 221 | if (!$gotSaved && !file_exists($cache_file)) { 222 | sendErrorImage("Failed to create image: $cache_file"); 223 | } 224 | 225 | return $cache_file; 226 | } 227 | 228 | // check if the file exists at all 229 | if (!file_exists($source_file)) { 230 | header("Status: 404 Not Found"); 231 | exit(); 232 | } 233 | 234 | /* check that PHP has the GD library available to use for image re-sizing */ 235 | if (!extension_loaded('gd')) { // it's not loaded 236 | if (!function_exists('dl') || !dl('gd.so')) { // and we can't load it either 237 | // no GD available, so deliver the image straight up 238 | trigger_error('You must enable the GD extension to make use of Adaptive Images', E_USER_WARNING); 239 | sendImage($source_file, $browser_cache); 240 | } 241 | } 242 | 243 | /* Check to see if a valid cookie exists */ 244 | if (isset($_COOKIE['resolution'])) { 245 | $cookie_value = $_COOKIE['resolution']; 246 | 247 | // does the cookie look valid? [whole number, comma, potential floating number] 248 | if (! preg_match("/^[0-9]+[,]*[0-9\.]+$/", "$cookie_value")) { // no it doesn't look valid 249 | setcookie("resolution", "$cookie_value", time()-100); // delete the mangled cookie 250 | } 251 | else { // the cookie is valid, do stuff with it 252 | $cookie_data = explode(",", $_COOKIE['resolution']); 253 | $client_width = (int) $cookie_data[0]; // the base resolution (CSS pixels) 254 | $total_width = $client_width; 255 | $pixel_density = 1; // set a default, used for non-retina style JS snippet 256 | if (@$cookie_data[1]) { // the device's pixel density factor (physical pixels per CSS pixel) 257 | $pixel_density = $cookie_data[1]; 258 | } 259 | 260 | rsort($resolutions); // make sure the supplied break-points are in reverse size order 261 | $resolution = $resolutions[0]; // by default use the largest supported break-point 262 | 263 | // if pixel density is not 1, then we need to be smart about adapting and fitting into the defined breakpoints 264 | if($pixel_density != 1) { 265 | $total_width = $client_width * $pixel_density; // required physical pixel width of the image 266 | 267 | // the required image width is bigger than any existing value in $resolutions 268 | if($total_width > $resolutions[0]){ 269 | // firstly, fit the CSS size into a break point ignoring the multiplier 270 | foreach ($resolutions as $break_point) { // filter down 271 | if ($total_width <= $break_point) { 272 | $resolution = $break_point; 273 | } 274 | } 275 | // now apply the multiplier 276 | $resolution = $resolution * $pixel_density; 277 | } 278 | // the required image fits into the existing breakpoints in $resolutions 279 | else { 280 | foreach ($resolutions as $break_point) { // filter down 281 | if ($total_width <= $break_point) { 282 | $resolution = $break_point; 283 | } 284 | } 285 | } 286 | } 287 | else { // pixel density is 1, just fit it into one of the breakpoints 288 | foreach ($resolutions as $break_point) { // filter down 289 | if ($total_width <= $break_point) { 290 | $resolution = $break_point; 291 | } 292 | } 293 | } 294 | } 295 | } 296 | 297 | /* No resolution was found (no cookie or invalid cookie) */ 298 | if (!$resolution) { 299 | // We send the lowest resolution for mobile-first approach, and highest otherwise 300 | $resolution = $is_mobile ? min($resolutions) : max($resolutions); 301 | } 302 | 303 | /* if the requested URL starts with a slash, remove the slash */ 304 | if(substr($requested_uri, 0,1) == "/") { 305 | $requested_uri = substr($requested_uri, 1); 306 | } 307 | 308 | /* whew might the cache file be? */ 309 | $cache_file = $document_root."/$cache_path/$resolution/".$requested_uri; 310 | 311 | /* Use the resolution value as a path variable and check to see if an image of the same name exists at that path */ 312 | if (file_exists($cache_file)) { // it exists cached at that size 313 | if ($watch_cache) { // if cache watching is enabled, compare cache and source modified dates to ensure the cache isn't stale 314 | $cache_file = refreshCache($source_file, $cache_file, $resolution); 315 | } 316 | 317 | sendImage($cache_file, $browser_cache); 318 | } 319 | 320 | /* It exists as a source file, and it doesn't exist cached - lets make one: */ 321 | $file = generateImage($source_file, $cache_file, $resolution); 322 | sendImage($file, $browser_cache); -------------------------------------------------------------------------------- /ai-cookie.php: -------------------------------------------------------------------------------- 1 | . That is now fixed. If AI detects retina displays it 8 | is now able to generate larger images than the top bounds set in $resolutions. 9 | 10 | version 1.5.1 (2012/04/14) ------------------------------------------------------------ 11 | 12 | ENHANCEMENT 13 | * JPGs are now created as Progressive rather than Optimised. 14 | 15 | Progressive JPGs are actually slightly smaller in file-size than Optimised JPGs, 16 | and have the benefit of appearing to load faster in modern browsers (they 17 | download in passes, gradually getting sharper). 18 | 19 | version 1.5 (2012/04/14) -------------------------------------------------------------- 20 | 21 | ENHANCEMENT 22 | * Much improved support for Retina and other high DPI devices 23 | 24 | NOTE: Retina support requires using alternate JavaScript: 25 | 26 | 27 | NOTE: If you see folders in the ai-cache directory which are *larger* than any 28 | defined in your $resolutions array, it is because someone with a high DPI / Retina 29 | display visited your site, and AI was able to generate the required image for them. 30 | 31 | DETAILS: 32 | Previous AI behaviour meant that supporting Retina required adding very high values 33 | in the $resolutions array. This is sub-optimal because: 34 | 35 | 1) This array is meant to be nothing more than the same values as your media query 36 | breakpoints. Adding larger ones isn't intuitive. 37 | 2) When no cookie is set, AI sends non-mobile devices the largest $resolution value, 38 | which in that case could be far too large for most people (2000px+) 39 | 40 | AI is now much smarter, you do not need to edit the $resolutions array; just leave 41 | that as your CSS MQ sizes. 42 | 43 | AI now auto-detects the pixel density of any high DPI device and either picks a 44 | matching size from the existing array, or creates new high-dpi images which are 45 | multiples of your chosen $resolutions values. 46 | 47 | version 1.4.1 (2012/03/28) ------------------------------------------------------------ 48 | 49 | ENHANCEMENT 50 | * More helpful error messages if something goes wrong. 51 | * Updated the documentation a little. 52 | 53 | version 1.4 (2012/02/19) -------------------------------------------------------------- 54 | 55 | ENHANCEMENT 56 | * Auto-creates the cache folder with the correct permissions. 57 | No need to manually create the ai-cache folder any more, AI does it for you. 58 | 59 | BUG FIX 60 | * Fixed an incorrect permission on created files, they're now 755 not 777. 61 | 62 | version 1.3.9 (2012/02/17) ------------------------------------------------------------ 63 | Thanks to Gerv 64 | 65 | ENHANCEMENT 66 | * Better detection of mobile device in the event cookies are not available. 67 | 68 | If cookies are unavailable AI resorts to basic UA sniffing. 69 | 70 | Previously AI assumed all devices are mobile and searched the UA string for a 71 | desktop OS. If found it overrode $mobile_first. However, this meant tablet 72 | devices got mobile sized images as their OS is not a desktop OS. 73 | 74 | Now switched to assume the device is a desktop, but AI searches the UA string for 75 | 'mobile' to switch to mobile first. All current mobile browsers behave in this 76 | way, meaning mobiles still get mobile resolution, but tablets and desktop get 77 | the largest configured resolution. 78 | 79 | * Removed $mobile_first as it is no longer needed (see above) 80 | 81 | version 1.3.8 (2012/01/24) ------------------------------------------------------------ 82 | 83 | BUG FIX 84 | * Eliminated occasional double-slash in $cache_file path due to $requested_uri 85 | sometimes starting with a / 86 | 87 | version 1.3.7 (2011/11/21) ------------------------------------------------------------ 88 | 89 | BUG FIX 90 | * A stupid mistake was causing the browser detect to always return false. 91 | This has been fixed. 92 | 93 | With this update Adaptive Images now detects if a user is running on a desktop OS 94 | and switches $mobile_first to FALSE in that case. This means that if no cookie is 95 | set and $mobile_first is TRUE the following will happen: 96 | 97 | On a mobile phone, the mobile sized image will be delivered. 98 | On a desktop, the highest resolution configured will be delivered. 99 | 100 | If a cookie is set, Adaptive Images will use the cookie value to determine the 101 | correct size image to send. 102 | 103 | version 1.3.6 (2011/11/11) ------------------------------------------------------------ 104 | 105 | NOTES 106 | * Added Linux desktop detection to the $mobile_first check routine (see previous 107 | changelog details) 108 | 109 | version 1.3.5 (2011/11/10) ------------------------------------------------------------ 110 | 111 | NEW FEATURE 112 | * To work around browser issues with unreliable cookie setting speed 113 | Adaptive Images now also checks the user agent string. 114 | 115 | If a desktop environment is detected, $mobile_first is automatically 116 | over-ridden to "FALSE". If not Adaptive Images will obey the configured 117 | value. 118 | 119 | This is a safety fallback and requires testing before I revert the 120 | default $mobile_first configured value to TRUE. 121 | 122 | version 1.3.4 (2011/11/10) ------------------------------------------------------------ 123 | 124 | BUG FIXES 125 | * URLs are now allowed to have spaces and other encoded characters in them 126 | * The sharpening function broke on libraries not compiled with the bundled version 127 | of PHP/GD. Adaptive Images now tests the imageconvolution function is available 128 | and gracefully handles cases where it isn't. 129 | 130 | NEW FEATURE 131 | * Instructions to take advantage of high-density displays like Apple's iPhone4 132 | are now included. Just use the alternative JavaScript snippet. 133 | 134 | NOTES 135 | * Set $mobile_first to default to FALSE. Browsers are inconsistent with their 136 | ability to set cookies before requesting s. For more information visit 137 | http://blog.yoav.ws/2011/09/Preloaders-cookies-and-race-conditions 138 | 139 | version 1.3.3 (2011/10/18) ------------------------------------------------------------ 140 | 141 | BUG FIXES 142 | * Added Gecko to the auto-disabled $mobile_first check: IE and Firefox don't 143 | honour $mobile_first. 144 | 145 | This is because both suffer from a race condition when setting the cookie. 146 | Sometimes it's set before are requested, sometimes not. This could produce 147 | desktop websites with mobile versions on first page load. 148 | 149 | OTHER IMPROVEMENTS 150 | * Changed the HTTP Cache Header from "public" to "private". 151 | 152 | This allows caches that are specific to one user (e.g., browser cache) to store 153 | the image in cache; shared caches (e.g., a proxy server) won't. This should avoid 154 | people behind proxies or other caching mechanisms experiencing wrongly sized images. 155 | 156 | version 1.3.2 (2011/09/06) ------------------------------------------------------------ 157 | Thanks to Oncle Tom 158 | 159 | BUG FIXES 160 | * Internet Explorer was not correctly setting the cookie, and thus breaking badly 161 | * Fixed a possible Cookie Injection, and optimised ai-cookie.php 162 | 163 | NOTES 164 | In testing it seems that Firefox is now behaving properly and setting the cookie 165 | in time. Thus, I've re-instated support for $mobile_first = TRUE on that browser 166 | 167 | version 1.3.1 (2011/09/06) ------------------------------------------------------------ 168 | Thanks to Emilio Bravo 169 | 170 | BUG FIXES 171 | * PNGs now maintain their alpha transparency when scaled down (previously got 172 | black backgrounds where transparency should be) 173 | 174 | version 1.3 (2011/09/04) -------------------------------------------------------------- 175 | Huge thanks to Jordi Boggiano 176 | 177 | NEW FEATURES 178 | * Finalised $mobile_first behaviour and defaulted it to TRUE 179 | BUG FIXES 180 | * Fixed typo which incorrectly set browser cache 181 | OTHER IMPROVEMENTS 182 | * When $mobile_first is FALSE now sends highest configured size instead of original 183 | * Refactored the PHP to be more robust and efficient 184 | * Simplified the JS to a single line and fixed pollution of the global namespace 185 | * Made the .htaccess rule more robust and accurate 186 | 187 | NOTES 188 | Firefox will not honour $mobile_first as set in the CONFIG section. This is 189 | intentional, and required due to a defect in Firefox's behaviour. It does not set 190 | cookies fast enough, and therefor on the first visit to a site would load the 191 | mobile sized image even if JS was enabled. Therefor, AI will not honour the 192 | $mobile_first setting on Firefox based browsers that have JavaScript disabled. 193 | 194 | version 1.3 beta (2011/08/31) --------------------------------------------------------- 195 | 196 | NEW FEATURES 197 | * Added support for Mobile First philosophy (see CONFIG, $mobile_first) 198 | 199 | NOTES 200 | When $mobile_first is set to TRUE it means the mobile sized version of the requested 201 | image will be sent in the event that no cookie is set (likely because JavaScript is 202 | unavailable). If FALSE, the original image is sent. 203 | 204 | There is a known problem with Firefox on a first visit to a site where $mobile_first 205 | is TRUE. It doesn't set the cookie fast enough, so the very first load sends the mobile 206 | size image. All page loads after are fine. Opera, Safari, and Chrome all work OK. 207 | 208 | version 1.2.2 (2011/08/30) ------------------------------------------------------------ 209 | NEW FEATURES 210 | * Unsupported no-javascript solution (see instructions.htm) 211 | 212 | version 1.2.1 (2011/08/26) ------------------------------------------------------------ 213 | NO NEW FEATURES 214 | I have re-branded Responsive-Images to "Adaptive-Images", firstly to help distinguish 215 | this project from the identically named project by Filament Group, and secondly 216 | because it's a more appropriate name. This system actively adapts existing images as 217 | well as "responding" to the visitors viewport to serve an appropriately sized version. 218 | 219 | NOTES 220 | The project is now available on GitHub for those who wish to track it there: 221 | https://github.com/MattWilcox/Adaptive-Images 222 | 223 | version 1.2 (2011/08/21) ------------------------------------------------------------ 224 | Contributions by Fabian Beiner, with thanks :) 225 | NEW FEATURES 226 | * Support for PNG and GIF images 227 | * Added ability to sharpen re-scaled images (see CONFIG, $sharpen) 228 | BUG FIXES 229 | * Better extension detection (.jpeg was failing) 230 | * First-run Firefox bug fixed. The JS must be in-line, in the ! 231 | DETAILS: 232 | Firefox (and potentially others, but not observed anywhere else) was requesting 233 | the first before it loaded the external javascript file, even when in the 234 | . This caused Firefox to load the full-resolution image the very first 235 | time the site was visited. All subsequent page views were fine. 236 | OTHER IMPROVEMENTS 237 | * Cleaned up the .htaccess file and included clear comments on use 238 | * Vastly improved instructions and examples on the downloadable zip 239 | * Since 1.1 fixed issues with browser cache, default cache time now set to 7 days 240 | * Refactored PHP code 241 | 242 | version 1.1 (2011/08/16) ------------------------------------------------------------ 243 | 244 | NEW FEATURES 245 | * Re-engineered the size detection methodology. 246 | 247 | Now detects maximum possible screen size of the device instead of the current 248 | window size. This removes the problem of visitors with small windows caching 249 | small images to the browser, then upon maximising the browser having too small 250 | images for the new screen size. It also simplifies the JS back down to its 251 | original "just dump the size into a cookie" functionality. 252 | 253 | This update removes the following: 254 | 255 | * All JS config options 256 | 257 | version 1.0 (2011/08/09) ------------------------------------------------------------ 258 | 259 | NEW FEATURES 260 | * Headers sent along with the image, for browser side caching (see CONFIG, $browser_cache) 261 | * JavaScript responds to window re-sizes, requests higher res images if required 262 | BUG FIXES 263 | * Fixed the MIME type for JPG's (image/jpeg not image/jpg) 264 | 265 | beta 2 (2011/08/04) ----------------------------------------------------------------- 266 | 267 | NEW FEATURES 268 | * Added the ability to control generated image quality (see CONFIG, $jpg_quality) 269 | * Added configurable resolution breakpoints (see CONFIG, $resolutions) 270 | * Optional Cache checking - defaults to on (see CONFIG, $watch_cache) 271 | BUG FIXES 272 | * The PHP now checks that the GD extension is loaded before proceeding 273 | * Clarified comments further 274 | 275 | beta 1 (2011/08/01) ----------------------------------------------------------------- 276 | 277 | NEW FEATURES 278 | * Initial public release 279 | * Commented the PHP for public consumption 280 | * Added user-configurable cache directory (see CONFIG, $cache_path) 281 | BUG FIXES 282 | * Didn't generate downscaled images due to typo -------------------------------------------------------------------------------- /instructions.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 18 | 19 | 20 | 21 |

Adaptive-Images Instructions

22 |

Basic instructions

23 |

Copy adaptive-images.php and .htaccess into the root directory of your site. If you already have a htaccess file DO NOT OVERWRITE IT, skip down to the advanced instructions.

24 |

Copy the following Javascript into the <head> of your site. It MUST go in the head as the first bit of JS, before any other JS. This is because it needs to work as soon as possible, any delay wil have adverse effects.

25 |
<script>document.cookie='resolution='+Math.max(screen.width,screen.height)+'; path=/';</script>
26 |

That's it, you're done. You should probably configure some preferences though.

27 |

NOTE 1: if you would like to take advantage of high-pixel density devices such as the iPhone4 or iPad3 Retina display you can use the following JavaScript instead. 28 | It will send higher-resolution images to such devices - be aware this will mean slower downloads for Retina users, but better images.

29 |
<script>document.cookie='resolution='+Math.max(screen.width,screen.height)+("devicePixelRatio" in window ? ","+devicePixelRatio : ",1")+'; path=/';</script>
30 |

NOTE 2: you do not need the ai-cookie.php file unless you are using the alternate method of detecting the users screen size. So delete it if you like, no one likes mess.

31 |

NOTE 3: If you are extra paranoid about security you can have the ai-cache directory sit outside of your web-root so it's not publicly accessible. Just set the paths properly in the .htaccess file and the .php file.

32 | 33 |

You already have a .htaccess file

34 |

I strongly advise you to duplicate that file so you can revert to it if things go pear-shaped.

35 |

Open your existing .htaccess file and edit the contents. You'll need to look and see if there is a section that begins with the following:

36 |

<IfModule mod_rewrite.c>

37 |

If there is, then you need to add the following lines into that block:

38 | 39 |
# Adaptive-Images -----------------------------------------------------------------------------------
 40 | 
 41 | # Add any directories you wish to omit from the Adaptive-Images process on a new line, as follows:
 42 | # RewriteCond %{REQUEST_URI} !some-directory
 43 | # RewriteCond %{REQUEST_URI} !another-directory
 44 | 
 45 | RewriteCond %{REQUEST_URI} !assets
 46 | 
 47 | # Send any GIF, JPG, or PNG request that IS NOT stored inside one of the above directories
 48 | # to adaptive-images.php so we can select appropriately sized versions
 49 | RewriteRule \.(?:jpe?g|gif|png)$ adaptive-images.php
 50 | 
 51 | # END Adaptive-Images -------------------------------------------------------------------------------
52 | 53 |

If you don't have a code block then simply copy and paste the following into your file instead:

54 | 55 |
<IfModule mod_rewrite.c>
 56 |   Options +FollowSymlinks
 57 |   RewriteEngine On
 58 | 
 59 |   # Adaptive-Images -----------------------------------------------------------------------------------
 60 | 
 61 |   # Add any directories you wish to omit from the Adaptive-Images process on a new line, as follows:
 62 |   # RewriteCond %{REQUEST_URI} !some-directory
 63 |   # RewriteCond %{REQUEST_URI} !another-directory
 64 | 
 65 |   RewriteCond %{REQUEST_URI} !assets
 66 | 
 67 |   # Send any GIF, JPG, or PNG request that IS NOT stored inside one of the above directories
 68 |   # to adaptive-images.php so we can select appropriately sized versions
 69 |   RewriteRule \.(?:jpe?g|gif|png)$ adaptive-images.php
 70 | 
 71 |   # END Adaptive-Images -------------------------------------------------------------------------------
 72 | </IfModule>
73 | 74 |

Additional settings and configuration

75 |

.htaccess

76 |

Instructions are in the file as comments (any line that starts with a # is a comment, and doesn't actually do anything)

77 |

Follow the instructions inside that code to specify any directories you don't want to use Adaptive-Images on.

78 | 79 |

PHP

80 |

You can now open the php file and have a play with the settings that are in the CONFIG area. By default it looks like this:

81 | 82 |
/* CONFIG ----------------------------------------------------------------------------------------------------------- */
 83 | 
 84 | $resolutions   = array(1382, 992, 768, 480); // the resolution break-points to use (screen widths, in pixels)
 85 | $cache_path    = "ai-cache"; // where to store the generated re-sized images. Specify from your document root!
 86 | $jpg_quality   = 80; // the quality of any generated JPGs on a scale of 0 to 100
 87 | $sharpen       = TRUE; // Shrinking images can blur details, perform a sharpen on re-scaled images?
 88 | $watch_cache   = TRUE; // check that the adapted image isn't stale (ensures updated source images are re-cached)
 89 | $browser_cache = 60*60*24*7; // How long the BROWSER cache should last (seconds, minutes, hours, days. 7days by default)
 90 | 
 91 | /* END CONFIG ----------------------------------------------------------------------------------------------------------
 92 | ------------------------ Don't edit anything after this line unless you know what you're doing -------------------------
 93 | --------------------------------------------------------------------------------------------------------------------- */
94 |

$resolutions are the screen widths we'll work with. In the default it will store a re-sized image for large screens, normal screens, tablets, phones, and tiny phones.

95 |

In general, if you're using a responsive design in CSS, these breakpoints will be exactly the same as the ones you use in your media queries.

96 |

$cache_path If you don't like the cached images being written to that folder, you can put it somewhere else. Just put the path to the folder here and make sure you create it on the server if for some reason that couldn't be done autmoatically by adaptive-images.php.

97 |

$sharpen Will perform a subtle sharpening on the rescaled images. Usually this is fine, but you may want to turn it off if your server is very very busy.

98 |

$watch_cache If your server gets very busy it may help performance to turn this to FALSE. It will mean however that you will have to manually clear out the cache directory if you change a resource file

99 | 100 |

Alternate method for those who can't rely on JavaScript

101 | 102 |

One of the weaknesses of the Adaptive Images process is its reliance on JavaScript to detect the visitors screen size, and set a cookie with that screen size inside it. The following is a solution for people who need the system to work without the use of JavaScript, but it does have a major caveat which is why this is not the default method, and why it is "unsupported" (I'm not going to troubleshoot problems you have with this method).

103 | 104 |

The alternative method

105 |

Do not use the JavaScript as explained above, but instead, ABOVE your normal CSS, add the following into the head:

106 |
<style>
107 |  @media only screen and (max-device-width: 479px) {
108 |    html { background-image:url(ai-cookie.php?maxwidth=479); } }
109 |  @media only screen and (min-device-width: 480px) and (max-device-width: 767px) {
110 |    html { background-image:url(ai-cookie.php?maxwidth=767); } }
111 |  @media only screen and (min-device-width: 768px) and (max-device-width: 991px) {
112 |    html { background-image:url(ai-cookie.php?maxwidth=991); } }
113 |  @media only screen and (min-device-width: 992px) and (max-device-width: 1381px) {
114 |    html { background-image:url(ai-cookie.php?maxwidth=1381); } }
115 |  @media only screen and (min-device-width: 1382px) {
116 |    html { background-image:url(ai-cookie.php?maxwidth=unknown); } }
117 | </style>
118 |

If you use this method you will need to ensure the widths here match those in your adaptive-images.php file, you will also need to have the ai-cookie.php file in the root of your website (no one else needs this file).

119 | 120 |

The caveat

121 |

Using this method instead of the JS method makes it likely that on the very first visit to your site, the images sent to the visitor will be the original full-scale versions. However, ALL subsequent pages on your site will work properly. What that means is that, really, this solution is only viable if you've got $mobile_first set to FALSE. Otherwise, the majority of people who visit your site will experience images too small for their computer on the very first visit.

122 |

The reason is to do with how browsers load web pages. The first thing a browser does is load the HTML, in the order it's written - so for a normal AI install it loads the HTML and see's the embeded JavaScript and immediately executes that JavaScript - which writes the cookie. It then carries on loading the rest of the page in the order it finds it. Long story short - it means that when it finds an image tag and asks the server for it, it already has a cookie stored.

123 |

That's not likely to be the case if you use the CSS method. Because the CSS method relies on an external file - it has to ask the server for the "background-image", which is really just a bit of PHP to set a cookie. The problem is that when a browser loads external files like that, it doesn't stop loading the HTML, it carries on doing that at the same time as waiting for the external file. Which means that it can get to an image tag before the server has finished loading that PHP file. This is only an issue on the very first page load, and AI has smart fallbacks to deal with a no-cookie situation.

124 | 125 |

Troubleshooting

126 |

Most of the time people report problems it is due to one of two things:

127 |

If images vanish, there is something wrong with your .htaccess configuration. This happens mostly on WordPress sites - it's because the server, and wordpress, have specific requirements that are different from most servers. You'll have to play about in the .htaccess file and read up on how to use ModRewrite.

128 |

If you're seeing error images (big black ones) That's AI working, so your .htaccess is fine. Read the messages on the image. Most of the time you'll only see this problem because your server requires less strict permissions to write to the disc. Try setting the ai-cache directory to 775, and if all else fails use 777 - but be aware this is not very secure if you're on a shared server, and you ought to instead contact your administrator to get the server set up properly.

129 | 130 | -------------------------------------------------------------------------------- /instructions_de.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 18 | 19 | 20 | 21 |

Adaptive-Images Installationsanweisungen

22 |

Basis Anweisungen

23 |

Kopieren Sie adaptive-images.php und .htaccess 24 | in das Hauptverzeichniss ihres Internetauftritts. 25 | Wenn Sie bereits eine htaccess Datei haben BITTE NICHT ÜBERSCHREIBEN, lesen sie die dafür vorgesehenen Instruktionen.

26 |

Erstellen Sie ein Verzeichniss mit dem Namen ai-cache im Hauptverzeichniss 27 | mit Schreibberechtigung (CHMOD 777).

28 |

Kopieren Sie folgendes Javascript in den <head> Bereich ihrer Seiten. 29 | Das Script MUSS sich im head Bereich befinden damit es ausgeführt wird bevor 30 | die gesamte Seite geladen ist und die ersten Bilder vom Server ausgeliefert werden.

31 |
<script>document.cookie='resolution='+Math.max(screen.width,
 32 | screen.height)+'; path=/';</script>
33 |

Das wars. Sie sind fertig

34 |

ANMERKUNG: Die ai-cookie.php Datei wird normalerweise nicht 35 | benötigt. Nur beim Einsatz der Alternativen Methode 36 | zum Feststellen der Displaygrösse wird sie benötigt ansonsten kann sie gelöscht werden.

37 | 38 |

Sie haben bereits eine .htaccess Datei

39 |

Sichern Sie bitte diese Datei bevor Sie Änderungen daran vornehmen.

40 |

Öffnen Sie bitte ihre bestehende .htaccess Datei und editieren Sie den Inhalt. 41 | Suchen Sie nach einem Abschnitt suchen der so beginnt:

42 |

<IfModule mod_rewrite.c>

43 |

Sollten Sie ihn gefunden haben kopieren Sie folgenden Code in den Bereich:

44 | 45 |
# Adaptive-Images -----------------------------------------------------------------------------------
 46 | 
 47 | # Add any directories you wish to omit from the Adaptive-Images process on a new 
 48 | line, as follows:
 49 | # RewriteCond %{REQUEST_URI} !some-directory
 50 | # RewriteCond %{REQUEST_URI} !another-directory
 51 | 
 52 | RewriteCond %{REQUEST_URI} !assets
 53 | 
 54 | # Send any GIF, JPG, or PNG request that IS NOT stored inside one of the above 
 55 | directories
 56 | # to adaptive-images.php so we can select appropriately sized versions
 57 | RewriteRule \.(?:jpe?g|gif|png)$ adaptive-images.php
 58 | 
 59 | # END Adaptive-Images -------------------------------------------------------------------------------
60 | 61 |

Gibt es keinen solchen Abschnitt in ihrer Datei kopieren Sie stattdesen folgenden Code in die Datei:

62 | 63 |
<IfModule mod_rewrite.c>
 64 |   Options +FollowSymlinks
 65 |   RewriteEngine On
 66 | 
 67 |   # Adaptive-Images -----------------------------------------------------------------------------------
 68 | 
 69 |   # Add any directories you wish to omit from the Adaptive-Images process on a 
 70 |   new line, as follows:
 71 |   # RewriteCond %{REQUEST_URI} !some-directory
 72 |   # RewriteCond %{REQUEST_URI} !another-directory
 73 | 
 74 |   RewriteCond %{REQUEST_URI} !assets
 75 | 
 76 |   # Send any GIF, JPG, or PNG request that IS NOT stored inside one of the above 
 77 |   directories
 78 |   # to adaptive-images.php so we can select appropriately sized versions
 79 |   RewriteRule \.(?:jpe?g|gif|png)$ adaptive-images.php
 80 | 
 81 |   # END Adaptive-Images -------------------------------------------------------------------------------
 82 | </IfModule>
83 | 84 |

Weitere Einstellungen

85 |

.htaccess

86 |

Anweisungen sind in der Datei als Kommentare enthalten (alle Zeilen die 87 | mit # beginnen sind Kommentare und werden nicht ausgeführt)

88 |

Folgen Sie den Anweisungen im Code um Verzeichnisse die nicht mit 89 | Adaptive-Images benutzt werden sollen einzutragen.

90 | 91 |

PHP

92 |

Sie können die PHP-Datei öffnen und die Einstellungen im CONFIG Bereich ändern. 93 | Die Standardwerte sehen so aus:

94 | 95 |
/* CONFIG ----------------------------------------------------------------------------------------------------------- */
 96 | 
 97 | $resolutions   = array(1382,992,768,480,320); // Die Auflösungsschritte für die Bilder erzeugt werden (Bildschirmbreite in Pixel)
 98 | $cache_path    = "ai-cache"; // Wo die verkleinerten Bilder gespeichert werden.  Der Ordner muss beschreibbar sein.
 99 | $jpg_quality   = 80; // Die Qualität der erzeugten JPGs 0 bis 100
100 | $sharpen       = TRUE; // Verkleinerte Bilder verlieren an Schärfe, bei TRUE werden die Bilder geschärft 
101 | $watch_cache   = TRUE; // stellt sicher das neu hochgeladene Bilder neu verkleinert werden
102 | $browser_cache = 60*60*24*7; // Die Zeit in Sekunden für den BROWSER cache (Standard 7 Tage)
103 | $mobile_first  = TRUE; // Ist kein Cookie vorhanden wird zuerst die mobile Version gesendet (wenn FALSE, wird das grösste Bild gesendet)
104 | 
105 | /* END CONFIG ----------------------------------------------------------------------------------------------------------
106 | ------------------------ Verändern Sie nichts nach dieser Zeile wenn Sie nicht wissen was Sie tun -------------------------
107 | --------------------------------------------------------------------------------------------------------------------- */
108 |

$resolutions sind die Bildschirmauflösungen mit denen gearbeitet wird. 109 | Als Standard werden verkleinerte Bilder für grosse Bildschirme, normale Bildschirme, 110 | Tablets, Smartphones, und Handys gespeichert.

111 |

Im allgemeinen, wenn Sie die CSS Methode nutzen, werden diese Auflösungen 112 | dieselben wie in den 'media queries' sein.

113 |

$cache_path Der Pfad in den die Bilder zwischengespeichert werden. 114 | Er kann beliebig geändert werden. Der Pfad wird hier eingetragen und es muss 115 | sichergestellt sein das er auf dem Server existiert.

116 |

$sharpen Die bilder werden nach dem Verkleinern geschärft. 117 | Normal funktioniert das gut sollte ihr Server sehr sehr ausgelastet sein kann es hier abgeschaltet werdn. .

118 |

$watch_cache Bei Performanceproblemen ihres Servers kann diese Option abgeschaltet werden. 119 | Sollten Sie allerdings ihre Quell-Bilder ersetzen müssen Sie den Cache Ordner manuell leeren.

120 |

$mobile_first Wenn TRUE und kein cookie ist gesetzt, sendet Adaptive 121 | Images Bilder in der 'mobilen' Auflösung. Wenn FALSE gesetzt ist werden die am 122 | höchten aufgelössten Bilder gesendet.

123 | 124 |

Alternative Methode ohne JavaScript

125 | 126 |

Eine Schwäche von Adaptive Images ist das JavaScript zum Erkennen der 127 | Bildschirmgrösse des Besuchers benötigt wird. 128 | Im folgenden wird eine Methode ohne Javascript gezeigt. 129 | Diese Methode funktioniert unter Vorbehalt wird allerdings vom Autor nicht empfohlen und nicht unterstützt. 130 |

131 | 132 |

Die alternative Methode

133 |

Benötigt kein JavaScript stattdessen aber, muss ÜBER ihrem normalen 134 | CSS, folgende Zeilen eingefügt werden:

135 |
<style>
136 |  @media only screen and (max-device-width: 479px) {
137 |    html { background-image:url(ai-cookie.php?maxwidth=479); } }
138 |  @media only screen and (min-device-width: 480px) and (max-device-width: 767px) {
139 |    html { background-image:url(ai-cookie.php?maxwidth=767); } }
140 |  @media only screen and (min-device-width: 768px) and (max-device-width: 991px) {
141 |    html { background-image:url(ai-cookie.php?maxwidth=991); } }
142 |  @media only screen and (min-device-width: 992px) and (max-device-width: 1381px) {
143 |    html { background-image:url(ai-cookie.php?maxwidth=1381); } }
144 |  @media only screen and (min-device-width: 1382px) {
145 |    html { background-image:url(ai-cookie.php?maxwidth=unknown); } }
146 | </style>
147 |

Wenn Sie diese Mehode verwenden müssen Sie sicherstellen das die verwendeten 148 | Bildschirmauflösungen dennen in Ihrer adaptive-images.php Datei entsprechen, 149 | Sie benötigen zudem die ai-cookie.php Datei im Hauptverzeichniss ihres Internetauftritts. 150 | (ansonsten wird diese Datei nicht benötigt).

151 | 152 |

Der Vorbehalt

153 |

Benutzen Sie diese Methode anstatt JS ist es möglich das besucher bei ihrem 154 | ersten Besuch ihrer Seiten, die original hoch aufgelössten Bilder gesendet bekommen. 155 | ALLE Seiten ihres Auftritts werden wie vorgesehen funktionieren. 156 | Das bedeutet allerdings das Sie die Option $mobile_first auf FALSE setzen müssen. 157 | Ansonsten werden die meisten ihrer Besucher feststellen das die angezeigten Bilder, 158 | bei ihrem ersten Besuch zu klein dargestellt werden. 159 | Otherwise, the majority of people who 160 |

161 |

Der Grund dafür ist die Reihenfolge wie Browser Internetseiten verarbeiten. 162 | Als erstes wird das HTML geladen, und in der Reihenfolge wie es geschrieben wurde abgearbeitet. 163 | Das eingebettete JavaScript wird sofort ausgeführt und erzeugt das Cookie. 164 | Danach werden Bilder in der Reihenfolge ihres Auftrettens geladen. das heisst 165 | werden die ersten Bilder vom Server angefordert ist das Cookie mit der Bildschirmgrösse 166 | bereits geschrieben.

167 |

Das ist bei der CSS Methode nicht unbedingt der Fall. Die CSS 168 | Methode setzt eine externe Datei voraus - sie fordert vom Server 169 | "background-image" an, welche von der PHP Datei nur benötigt wird um das Cookie zu setzen. 170 | Das Problem ist das der Browser beim laden der externen Datein nicht anhält, 171 | er arbeitet weiter während er auf die externe datei wartet. Das bedeutet das 172 | schon Bilddateien angefordert werden können bevor die PHP Datei abgearbeitet wurde 173 | und somit noch kein Cookie gesetzt wurde. Das wiederum heisst, daß wenn $mobile_first TRUE ist 174 | die für mobile Geräte verkleinerten Bilder gesendet werden. Aber nur wenn die 175 | allererste Seite geladen wird.

176 | 177 | -------------------------------------------------------------------------------- /instructions_tr.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 18 | 19 | 20 | 21 |

Adaptive-Images Kullanım Kılavuzu

22 |

Temel yönergeler

23 |

adaptive-images.php ve .htaccess dosyalarını sitenizin ana dizinine yerleştirin. Eğer halihazırda bir htaccess dosyanız varsa onu SİLMEYİN, ileri düzey yönergeleri okuyun.

24 |

Aşağıdaki Javascript kodunu sitenize yerleştirin. Bu kod, head taginin içinde ve diğer tüm javascript kodlarından önce yerleştirilmek ZORUNDA. Çünü her türlü gecikmenin sonuçları olabilir ve düzgün çalışabilmesi için olabildiğince erken yüklenmesi gerekiyor.

25 |
<script>document.cookie='resolution='+Math.max(screen.width,screen.height)+'; path=/';</script>
26 |

Hepsi bu kadar. Yine de bazı ayarları yapmanız gerekecektir.

27 |

NOT 1: Eğer iPhone4 veya iPad3 Retina gibi cihazların yüksek çözünürlüğünden faydalanmak isterseniz aşağıdaki Javascript'i kullanın. 28 | Bu sayede bu tarz cihazlara yüksek çözünürlüklü resimler göndereceksiniz, ama bu da download süresini yavaşlatacaktır tabii ki.

29 |
<script>document.cookie='resolution='+Math.max(screen.width,screen.height)+("devicePixelRatio" in window ? ","+devicePixelRatio : ",1")+'; path=/';</script>
30 |

NOT 2: Eğer ekran çözünürlüğünü algılamak için alternatif metodları kullanmayacaksanız ai-cookie.php dosyasına ihtiyacınız olmayacak. Yani isterseniz silin, kimse kalabalığı sevmez.

31 |

NOT 3: Eğer güvenlik konusunda fazla pimpirikliyseniz ai-cache klasörünü web rootunuzun dışına taşıyabilirsiniz, dışarıya erişimini kapatmak için. PHP ve .htaccess dosyalarındaki klasör ayarlarını da buna göre düzenleyin.

32 | 33 |

Zaten .htaccess dosyanız mı var?

34 |

Mevcut dosyanızın bir kopyasını almayı şiddetle tavsiye ediyorum. Bir aksilik durumunda hemen orijinal haline dönebilin diye.

35 |

Mevcut .htaccess dosyanızı açın ve aşağıdaki kodlarla başlayan bir bölüm var mı diye kontrol edin:

36 |

<IfModule mod_rewrite.c>

37 |

Eğer varsa, o bloğun içine şu kodları ekleyin:

38 | 39 |
# Adaptive-Images -----------------------------------------------------------------------------------
 40 | 
 41 | # Add any directories you wish to omit from the Adaptive-Images process on a new line, as follows:
 42 | # RewriteCond %{REQUEST_URI} !some-directory
 43 | # RewriteCond %{REQUEST_URI} !another-directory
 44 | 
 45 | RewriteCond %{REQUEST_URI} !assets
 46 | 
 47 | # Send any GIF, JPG, or PNG request that IS NOT stored inside one of the above directories
 48 | # to adaptive-images.php so we can select appropriately sized versions
 49 | RewriteRule \.(?:jpe?g|gif|png)$ adaptive-images.php
 50 | 
 51 | # END Adaptive-Images -------------------------------------------------------------------------------
52 | 53 |

Eğer böyle bir blok yoksa basitçe şu kodu kopyalayın ve htaccess dosyanızın içine yapıştırın:

54 | 55 |
<IfModule mod_rewrite.c>
 56 |   Options +FollowSymlinks
 57 |   RewriteEngine On
 58 | 
 59 |   # Adaptive-Images -----------------------------------------------------------------------------------
 60 | 
 61 |   # Her bir satıra aşağıdaki formatı kullanarak Adaptive-Images'ın çalışmamasını istediğiniz dizinleri belirtebilirsiniz:
 62 |   # RewriteCond %{REQUEST_URI} !some-directory
 63 |   # RewriteCond %{REQUEST_URI} !another-directory
 64 | 
 65 |   RewriteCond %{REQUEST_URI} !assets
 66 | 
 67 |   # Yukarıda belirtilmeyen klasörlerlerdeki tüm GIF, JPG ve PNG'leri
 68 |   # adaptive.images.php'ye yönlendir. Böylece farklı boyutlardan doğru olana ulaşmayı sağla
 69 |   RewriteRule \.(?:jpe?g|gif|png)$ adaptive-images.php
 70 | 
 71 |   # END Adaptive-Images -------------------------------------------------------------------------------
 72 | </IfModule>
73 | 74 |

Ek ayarlar

75 |

.htaccess

76 |

Yönergeler yorum satırı olarak ekldndi. (# ile başayan satırlar yorum satırıdır ve bir işleve sahip değiller.)

77 |

Bu yorum satırlarındaki yönergeleri izleyerek belirli dizinlerde Adaptive-Images'in çalışmamasını sağlayabilirsiniz.

78 | 79 |

PHP

80 |

Şimdi PHP dosysını açıp CONFIG alanının içindeki ayarları kendinize göre düzenleyebilirsiniz. Orijinal hali şöyle:

81 | 82 |
/* CONFIG ----------------------------------------------------------------------------------------------------------- */
 83 | 
 84 | $resolutions   = array(1382, 992, 768, 480); // çözünürlüğe göre kırılma noktaları (ekran genişliği, pixel birimiyle)
 85 | $cache_path    = "ai-cache"; // boyutlandırılmış resimlerin tutulacağı dizin. Ana dizininize göre belirtin!
 86 | $jpg_quality   = 80; // oluşturulan JPG'in 100 üzerinden kalitesi
 87 | $sharpen       = TRUE; // resimleri küçültmek detaylarda bulanıklığa sebep olabilir, boyutlandırılmış resimlerde keskinleştirme yapılsın mı?
 88 | $watch_cache   = TRUE; // oluşturulmuş resimlerin miyadını doldurup doldurmadığını kontrol eder (aynı zamanda yeni oluşturulan resimlerin yeniden önbelleklenmesini sağlar)
 89 | $browser_cache = 60*60*24*7; // Tarayıcı önbelleğinin ne kadar geçerli kalmalı? (saniye, dakika, saat, gün. Orijinal halinde 7 gündür)
 90 | 
 91 | /* END CONFIG ----------------------------------------------------------------------------------------------------------
 92 | ------------------------- Yaptığınız şeye hakim değilseniz aşağıdaki satırlara dokunmayınız  ---------------------------
 93 | --------------------------------------------------------------------------------------------------------------------- */
94 |

$resolutions üstünde çalışacağımız ekran genişlikleridir. Orijinal halinde; geniş ekranlar, normal ekranlar, tablet, telefon ve küçük telefonlar için farklı boyutlar tutar.

95 |

Genellikle, CSS ile responsive bir tasarım kullanıyorsanız, bu boyutlar media query'lerinizdeki kırılma noktalarıyla aynı değerlere sahip olacaktır.

96 |

$cache_path Eğer önbelleklenmiş resimlerin bu klasöre atılmasını istemiyorsanız, başka bir klasör belirtebilirsiniz. Dizini kendi istediğinizle değiştirin ve sunucunuzda bu klasörden oluşturmayı unutmayın. adaptive-images.php bu klasörü otomatik olarak oluşturamayabilir.

97 |

$sharpen boyutlanmış resimlerde keskinleştirme işlemini yapar. Genellikle bunun çalışması işe yarardır, ama sunucunuz çok yoğunsa bunu kapatmayı düşünebilirsiniz.

98 |

$watch_cache Sunucunuz çok yoğunsa, performans artışı için bu özelliği FALSE değeriyle kapatmanız işinize yarayabilir. Ama bu da bir resmi değiştirdiğinizde, önbellek klasörünü sizin temizlemenizi gerektirir.

99 | 100 |

Javasript kullanamayacaklar için alternatif metodlar

101 | 102 |

One of the weaknesses of the Adaptive Images process is its reliance on JavaScript to detect the visitors screen size, and set a cookie with that screen size inside it. The following is a solution for people who need the system to work without the use of JavaScript, but it does have a major caveat which is why this is not the default method, and why it is "unsupported" (I'm not going to troubleshoot problems you have with this method).

103 | 104 |

Alternatif metod

105 |

Yukarıdaki Javascript kodlarını kullanmak yerine sitenizin CSS kodlarının ÜSTÜNE aşağıdaki kodları ekleyin (head içerisinde):

106 |
<style>
107 |  @media only screen and (max-device-width: 479px) {
108 |    html { background-image:url(ai-cookie.php?maxwidth=479); } }
109 |  @media only screen and (min-device-width: 480px) and (max-device-width: 767px) {
110 |    html { background-image:url(ai-cookie.php?maxwidth=767); } }
111 |  @media only screen and (min-device-width: 768px) and (max-device-width: 991px) {
112 |    html { background-image:url(ai-cookie.php?maxwidth=991); } }
113 |  @media only screen and (min-device-width: 992px) and (max-device-width: 1381px) {
114 |    html { background-image:url(ai-cookie.php?maxwidth=1381); } }
115 |  @media only screen and (min-device-width: 1382px) {
116 |    html { background-image:url(ai-cookie.php?maxwidth=unknown); } }
117 | </style>
118 |

Eğer bu yolu seçtiyseniz CSS'teki genişliklerin adaptive-images.php dosyasındakilerle eşleştiğinizden emin olun. Ayrıca ana dizinizde ai-cookie.php dosyasının da olması gerekir (bu yolu kullanmayacaksanız bu dosyaya hiç ihtiyacınız yok).

119 | 120 |

Uyarı

121 |

Javascript yerine bu metodu kullanmanız durumunda, kullanıcıların sitenizi ilk ziyaretinde resimler orijinal boyutlarıyla yüklenir. Ama tüm alt sayfalar doğru şekilde çalışacaktır! Bu da şu demek: bu çözüm sadece $mobile_first ayarının FALSE olduğu durumlarda mantıklı olacaktır. Aksi halde, ziyaretçilerinizin büyük bir çoğunluğu sitenizi ilk ziyaretlerinde çok küçük resimlerle karşılaşacaklar.

122 |

Bunun sebebi de tarayıcıların siteleri yükleme şekilleridir. Bir tarayıcının HTML'i yüklerken yaptığı ilk şey, yazılan sırasıyla, normal bir AI kurulumunda önce HTML'i yükler ve gömülen Javascriptleri çalıştırır (Cookieleri hazırlayan kod). Daha sonra, sayfanın kalanını yüklemeye sırayla devam eder. Uzun lafın kısası, bu sayede, tarayıcı bir resim etiketi bulup onu yüklemeye başladığında, çerezler çoktan ayarlanmış olurlar.

123 |

CSS metodunu kullandığınızda işler bu şekilde yürümez. Çünkü CSS metodu başka bir dosyaya dayanır. "background-image" için bir PHP dosyasına ulaşır. Bu PHP dosyasının da tek işlevi ufak kodlarla diğer metodda Javascript'in yaptığı gibi çerezi tanımlamaktır. Buradaki sorun, tarayıcılar böyle dış dosyalara erişirken sayfayı yüklemeyi bırakmazlar. Bir yandan bu dosyadan yanıt beklerken, bir yandan da diğer dosyaları yüklemeye devam eder. Bu da demek ki, bir resime bizim mucizevi php dosyamızdan önce ulaşabilir. Bu sadece ilk ziyarette yaşanacak bir sorundur, ve AI no-cookie durumlarıyla baş etmek için başka sihirli yollar dener.

124 | 125 |

Olası aksaklıklar

126 |

Çoğu zaman kullanıcıların yaşadığı sorunlar temel iki şeye dayanır:

127 |

Eğer resimler yok oluyorsa, .htaccess ayarlarınızda bir sorun vardır. Genellikle Wordpress sitelerinde bu sorun görülür. Çünkü sunucu ve wordpress çoğu sunucudan farklı şeylere ihtiyaç duyar. Htaccess dosyanızla biraz oynamanız ve yukarıdaki ModRewrite ile ilgili bölümü tekrar okumanız sorunu çözecektir.

128 |

Eğer siyah hata sayfaları görüyorsanız AI çalışıyor, yani .htaccess sorunsuz çalışıyor. Resimdeki mesjaları okuyun. Çoğu zaman bu hatayı görürsünüz çünkü sunucunuz dosya yazımları için güçlü izinler ister. ai-cache klasörünün yazım izinlerini 775, o da olmazsa 777'ye getirmeyi deneyin. Ama paylaşılan sunucularda bu izinlerin çok güvenli olmayacağını ve sunucunuzun yöneticisiyle görüşmenizin iyi olacağını bilin.

129 | 130 | -------------------------------------------------------------------------------- /readme.textile: -------------------------------------------------------------------------------- 1 | h1. Adaptive Images 2 | 3 | Is a solution to automatically create, cache, and deliver device-appropriate versions of your website's content images. It does not require you to change your mark-up. It is intended for use with "Responsive Designs":http://www.abookapart.com/products/responsive-web-design and to be combined with "Fluid Image":http://unstoppablerobotninja.com/entry/fluid-images/ techniques. 4 | 5 | h2. Project status 6 | 7 | I am not maintaining this project any longer. 8 | 9 | This is an old project, and still works as intended, with little need for new features (hence the lack of updates). That said; if you are building a new website I would *strongly recommend* looking into HTLM's new 'picture' tag, and the srcset and sizes properties now available on regular img tags. These were not available at the time of making AI, have since become a standard, and in many cases these are more appropriate solutions today. 10 | 11 | h2. Benefits 12 | 13 | * Ensures you and your visitors are not wasting bandwidth delivering images at a higher resolution than the vistor needs. 14 | * Will work on your existing site, as it requires no changes to your mark-up. 15 | * Is device agnostic (it works by detecting the size of the visitors screen) 16 | * Is CMS agnostic (it manages its own image re-sizing, and will work on any CMS or even on flat HTML pages) 17 | * Is entirely automatic. Once added to your site, you need do no further work. 18 | * Highly configurable 19 | ** Set the resolutions you want to become adaptive (usually the same as the ones in your CSS @media queries) 20 | ** Choose where you want the cached files to be stored 21 | ** Configure directories to ignore (protect certain directories so AI is not applied to images within them) 22 | 23 | Find out more, and view examples at "http://adaptive-images.com":http://adaptive-images.com 24 | 25 | h2. Legal 26 | 27 | Adaptive Images by Matt Wilcox is licensed under a "Creative Commons Attribution 3.0 Unported License":http://creativecommons.org/licenses/by/3.0/ 28 | --------------------------------------------------------------------------------