Adaptive Images是一個PHP編寫的工具,它可將圖像傳輸到小型移動設備上。應用嵌入式解決方案會根據設備屏幕大小 自動創建、捕捉、傳輸圖片,而不需要額外改動圖像。
一、在圖片文件夾創建.htaccess文件
<IfModule mod_rewrite.c> Options +FollowSymlinks RewriteEngine On # Adaptive-Images ----------------------------------------------------------------------------------- # Add any directories you wish to omit from the Adaptive-Images process on a new line, as follows: # RewriteCond %{REQUEST_URI} !ignore-this-directory # RewriteCond %{REQUEST_URI} !and-ignore-this-directory-too RewriteCond %{REQUEST_URI} !assets # Send any GIF, JPG, or PNG request that IS NOT stored inside one of the above directories # to adaptive-images.php so we can select appropriately sized versions RewriteRule .(?:jpe?g|gif|png)$ adaptive-images.php # END Adaptive-Images ------------------------------------------------------------------------------- </IfModule>
二、將如下JS腳本復制到每個需要自適應圖片的網頁的頭部
<script>document.cookie='resolution='+Math.max(screen.width,screen.height)+'; path=/';</script>
三、HTML代碼
<!doctype html> <html> <head> <meta charset="UTF-8" /> <title>test</title> <!-- The Adaptive Images JavaScript --> <script>document.cookie='resolution='+Math.max(screen.width,screen.height)+'; path=/';</script> </head> <body> <div id="example"> <h2>Example in action</h2> <div class="gallery"> <div class="image_main"> <img src="creepy.jpg" alt="" /> </div> </div> </div> </body> </html>
項目地址:http://adaptive-images.com/
*