You are here

README.txt in Adaptive Image Styles (ais) 7

Adaptive Image Styles
=====================

Description
-----------

This module allows any image to be adaptive simply by setting it to be
rendered with the 'adaptive' style.  This module also integrates with
the Media module, and adds an adaptive option selectable from the media
displays.

Which image styles are used to generate the adapted images is also
configurable.  The adaptive image styles module offers an easy way to
make any images adaptive.

Simply choosing to display the image with the "adaptive" image style with
make the image adapt to the clients window width.  The Adaptive Image
Styles administration page provides an interface for choosing which image
styles are using to generate the adapted images and set the threshold
for when they are chosen.  The threshold refers to browser window width.

Example:
  If there are three image style selected, with thresholds
    of 480, 768, and 992.
  If the window width is from 0 - 480 pixels, the adaptive image will be
    displayed using the image style with a threshold of 480.
  From 481 - 768, the 768 image style will be used, and any wider than 769,
    the image style with the threshold of 992 will be used.


Caveats
-------

AIS works using an htaccess rewrite rule when using Apache or web server configuration when using NginX.

If a client has JavaScript disabled, the original image will be displayed.


Non-Apache / NGINX server configuration references
--------------------------------------------------

Web tool to convert htaccess rules to NGINX rules:
	http://winginx.com/htaccess

Related, solved issues:

Validate NginX rules:
#1669182: Running this module on a non-apache server
	https://drupal.org/node/1669182

Octopus / NGINX:
#1452732: adaptive image styles for my responsive design.
	https://drupal.org/node/1452732


Installation
------------

  1. Enable the module
  2. Patch Drupal's .htaccess file
  3. Correctly configure the RewriteBase in Drupal's .htaccess file.
  4. Display your images and media with the 'adaptive' image style
  5. Configure which images styles are used by AIS


To patch Drupal's htaccess file with patch, run the following from you
Drupal root:

$ patch < sites/all/modules/ais/ais.htaccess.patch

To patch Drupal's htaccess file manually:

Add following:

# AIS: Adaptive Image Style
  RewriteBase /
  RewriteCond %{REQUEST_URI} ^(.+)/files/styles/adaptive/(.+)$
  RewriteCond %{REQUEST_URI} !/modules/image/sample.png
  RewriteCond %{HTTP_COOKIE} ais=([a-z0-9_-]+)
  RewriteRule ^(.+)/files/styles/adaptive/(.+)$ $1/files/styles/%1/$2 [R=302,L]

Into the .htaccess file before the following lines:

 # Pass all requests not referring directly to files in the filesystem to
 # index.php. Clean URLs are handled in drupal_environment_initialize().
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_URI} !=/favicon.ico
 RewriteRule ^ index.php [L]

NOTE:
You must set the RewriteBase correctly.
If Drupal is at the root of your domain, it should be set to "RewriteBase /".
If Drupal is in a directory (like http://www.example.com/mydirectory),
it must be set to "RewriteBase /mydirectory".

If you've modified your .htaccess file correctly (and you have no other
modification), your .htaccess file should look like the "ais.htaccess.example"
file included with this module.


Running AIS on NginX
--------------------

The following NginX configuration should work with AIS:

location ~* /(?:.+)/files/styles/adaptive/(?:.+)$ {
  if ( $http_cookie ~* "ais=(?<ais_cookie>[a-z0-9-_]+)" ) {
    rewrite ^/(.+)/files/styles/adaptive/(.+)$ /$1/files/styles/$ais_cookie/$2 last;
  }
  access_log off;
  add_header X-Header "AIS Generator 1.0";
  set $nocache_details "Skip";
  try_files  $uri @drupal;
}


Author
------

David Pascoe-Deslauriers, Sponsored by Coldfront Labs Inc.

File

README.txt
View source
  1. Adaptive Image Styles
  2. =====================
  3. Description
  4. -----------
  5. This module allows any image to be adaptive simply by setting it to be
  6. rendered with the 'adaptive' style. This module also integrates with
  7. the Media module, and adds an adaptive option selectable from the media
  8. displays.
  9. Which image styles are used to generate the adapted images is also
  10. configurable. The adaptive image styles module offers an easy way to
  11. make any images adaptive.
  12. Simply choosing to display the image with the "adaptive" image style with
  13. make the image adapt to the clients window width. The Adaptive Image
  14. Styles administration page provides an interface for choosing which image
  15. styles are using to generate the adapted images and set the threshold
  16. for when they are chosen. The threshold refers to browser window width.
  17. Example:
  18. If there are three image style selected, with thresholds
  19. of 480, 768, and 992.
  20. If the window width is from 0 - 480 pixels, the adaptive image will be
  21. displayed using the image style with a threshold of 480.
  22. From 481 - 768, the 768 image style will be used, and any wider than 769,
  23. the image style with the threshold of 992 will be used.
  24. Caveats
  25. -------
  26. AIS works using an htaccess rewrite rule when using Apache or web server configuration when using NginX.
  27. If a client has JavaScript disabled, the original image will be displayed.
  28. Non-Apache / NGINX server configuration references
  29. --------------------------------------------------
  30. Web tool to convert htaccess rules to NGINX rules:
  31. http://winginx.com/htaccess
  32. Related, solved issues:
  33. Validate NginX rules:
  34. #1669182: Running this module on a non-apache server
  35. https://drupal.org/node/1669182
  36. Octopus / NGINX:
  37. #1452732: adaptive image styles for my responsive design.
  38. https://drupal.org/node/1452732
  39. Installation
  40. ------------
  41. 1. Enable the module
  42. 2. Patch Drupal's .htaccess file
  43. 3. Correctly configure the RewriteBase in Drupal's .htaccess file.
  44. 4. Display your images and media with the 'adaptive' image style
  45. 5. Configure which images styles are used by AIS
  46. To patch Drupal's htaccess file with patch, run the following from you
  47. Drupal root:
  48. $ patch < sites/all/modules/ais/ais.htaccess.patch
  49. To patch Drupal's htaccess file manually:
  50. Add following:
  51. # AIS: Adaptive Image Style
  52. RewriteBase /
  53. RewriteCond %{REQUEST_URI} ^(.+)/files/styles/adaptive/(.+)$
  54. RewriteCond %{REQUEST_URI} !/modules/image/sample.png
  55. RewriteCond %{HTTP_COOKIE} ais=([a-z0-9_-]+)
  56. RewriteRule ^(.+)/files/styles/adaptive/(.+)$ $1/files/styles/%1/$2 [R=302,L]
  57. Into the .htaccess file before the following lines:
  58. # Pass all requests not referring directly to files in the filesystem to
  59. # index.php. Clean URLs are handled in drupal_environment_initialize().
  60. RewriteCond %{REQUEST_FILENAME} !-f
  61. RewriteCond %{REQUEST_FILENAME} !-d
  62. RewriteCond %{REQUEST_URI} !=/favicon.ico
  63. RewriteRule ^ index.php [L]
  64. NOTE:
  65. You must set the RewriteBase correctly.
  66. If Drupal is at the root of your domain, it should be set to "RewriteBase /".
  67. If Drupal is in a directory (like http://www.example.com/mydirectory),
  68. it must be set to "RewriteBase /mydirectory".
  69. If you've modified your .htaccess file correctly (and you have no other
  70. modification), your .htaccess file should look like the "ais.htaccess.example"
  71. file included with this module.
  72. Running AIS on NginX
  73. --------------------
  74. The following NginX configuration should work with AIS:
  75. location ~* /(?:.+)/files/styles/adaptive/(?:.+)$ {
  76. if ( $http_cookie ~* "ais=(?[a-z0-9-_]+)" ) {
  77. rewrite ^/(.+)/files/styles/adaptive/(.+)$ /$1/files/styles/$ais_cookie/$2 last;
  78. }
  79. access_log off;
  80. add_header X-Header "AIS Generator 1.0";
  81. set $nocache_details "Skip";
  82. try_files $uri @drupal;
  83. }
  84. Author
  85. ------
  86. David Pascoe-Deslauriers, Sponsored by Coldfront Labs Inc.