source: spip-zone/_plugins_/adaptive_images/trunk/lib/AdaptiveImages/README.md @ 79131

Last change on this file since 79131 was 79131, checked in by cedric@…, 6 years ago

mise a jour de la lib AdaptiveImages?

File size: 3.8 KB
Line 
1AdaptiveImages
2==============
3
4## What is it?
5This is the sandalone PHP implementation of "3-layer technique" for Adaptive Images generation.
6See <http://blog.nursit.net/Adaptive-Images-et-Responsive-Web.html> for technical explanations and justifications.
7
8## Requirements
9
10PHP>=5.1 with GD library
11
12
13## Using
14
15### Simple use-case
16
17Call `adaptHTMLPage` method on your HTML page with optional maximum display width of images in your HTML page.
18
19<pre>
20require_once "AdaptiveImages.php"
21$AdaptiveImage = AdaptiveImages::getInstance();
22$html = $AdaptiveImage->adaptHTMLPage($html,780);
23</pre>
24
25First view of page with adaptive Images can timeout due to all the images to generate. Reload the page to complete image generation.
26
27### Caching
28
29If your CMS/application allow caching of HTML part of pages, apply `adaptHTMLPart` method on this part in order to cache Adaptive Images
30
31<pre>
32require_once "AdaptiveImages.php"
33$AdaptiveImage = AdaptiveImages::getInstance();
34return $AdaptiveImage->adaptHTMLPart($texte, 780);
35</pre>
36
37then recall `adaptHTMLPage` method on full HTML page to finish the job
38
39<pre>
40$AdaptiveImage = AdaptiveImages::getInstance();
41$html = $AdaptiveImage->adaptHTMLPage($html,780);
42</pre>
43
44### OnDemand images generation
45
46To avoid timeout on first view of HTML page you can activate OnDemand images generation. In this case, only URL of adapted images will be computed, and you need to use a Rewrite Rules and a router to call `AdaptiveImages::deliverBkptImage`.
47
48For instance with SPIP CMS :
49
50#### Rewrite Rule
51
52<pre>
53###
54# If file or directory exists deliver it and ignore others rewrite rules
55RewriteCond %{REQUEST_FILENAME} -f
56RewriteRule "." - [skip=100]
57RewriteCond %{REQUEST_FILENAME} -d
58RewriteRule "." - [skip=100]
59#
60###
61
62###
63# Adaptive Images : call action_adapt_img_dist() function if image not available
64
65RewriteRule \badapt-img/(\d+/\d\dx/.*)$ spip.php?action=adapt_img&arg=$1 [QSA,L]
66
67# Fin des Adaptive Images
68###
69</pre>
70
71#### Router
72
73<pre>
74function action_adapt_img_dist(){
75
76        $AdaptiveImage = AdaptiveImages::getInstance();
77        try {
78                $AdaptiveImage->deliverBkptImage(_request('arg'));
79        }
80        catch (Exception $e){
81                http_status(404);
82                die('Error : '.$e->getMessage());
83        }
84        exit;
85}
86</pre>
87
88## Advanced Configuration
89
90* Directory for storing adaptive images
91  <pre>$AdaptiveImage->destDirectory = "local/adapt-img/";</pre>
92* Default Maximum display width for images
93  <pre>$AdaptiveImage->maxWidth1x = 640;</pre>
94* Minimum display width for adaptive images (smaller will be unchanged)
95  <pre>$AdaptiveImage->minWidth1x = 320;</pre>
96* Maximum width for delivering mobile version in data-src-mobile=""
97  <pre>$AdaptiveImage->maxWidthMobileVersion = 320;</pre>
98* Activade On-Demand images generation
99  <pre>$AdaptiveImage->onDemandImages = true;</pre>
100* Background color for JPG lowsrc generation (if source has transparency layer)
101  <pre>$AdaptiveImage->lowsrcJpgBgColor = '#eeeeee';</pre>
102* Breakpoints width for image generation
103  <pre>$AdaptiveImage->defaultBkpts = array(160,320,480,640,960,1440);</pre>
104* Allow progressive rendering og PNG and GIF even without JS :
105  <pre>$AdaptiveImage->nojsPngGifProgressiveRendering = true;</pre>
106* JPG compression quality for JPG lowsrc
107  <pre>$AdaptiveImage->lowsrcJpgQuality = 10;</pre>
108* JPG compression quality for 1x JPG images
109  <pre>$AdaptiveImage->x10JpgQuality = 75;</pre>
110* JPG compression quality for 1.5x JPG images
111  <pre>$AdaptiveImage->x15JpgQuality = 65;</pre>
112* JPG compression quality for 2x JPG images
113  <pre>$AdaptiveImage->x15JpgQuality = 45;</pre>
114* GD maximum px size (width x height) of image that can be manipulated without Fatal Memory Error (0=no limit)
115  <pre>$AdaptiveImage->maxImagePxGDMemoryLimit = 2000*2000;</pre>
116
117
118## Real-life use case
119
120See the implementation in SPIP CMS :
121http://zone.spip.org/trac/spip-zone/browser/_plugins_/adaptive_images/trunk/adaptive_images_options.php
Note: See TracBrowser for help on using the repository browser.