Adaptive Images是一个PHP编写的工具,它可将图像传输到小型移动设备上。应用嵌入式解决方案会根据设备屏幕大小 自动创建、捕捉、传输图片,而不需要额外改动图像。
一、在图片文件夹创建.htaccess文件
<IfModule mod_rewrite.c><br /> Options +FollowSymlinks<br /> RewriteEngine On<br /> # Adaptive-Images -----------------------------------------------------------------------------------<br /> # Add any directories you wish to omit from the Adaptive-Images process on a new line, as follows:<br /> # RewriteCond %{REQUEST_URI} !ignore-this-directory<br /> # RewriteCond %{REQUEST_URI} !and-ignore-this-directory-too<br /> RewriteCond %{REQUEST_URI} !assets<br /> # Send any GIF, JPG, or PNG request that IS NOT stored inside one of the above directories<br /> # to adaptive-images.php so we can select appropriately sized versions<br /> RewriteRule .(?:jpe?g|gif|png)$ adaptive-images.php<br /> # END Adaptive-Images -------------------------------------------------------------------------------<br /></IfModule>
二、将如下JS脚本复制到每个需要自适应图片的网页的头部
<script>document.cookie='resolution='+Math.max(screen.width,screen.height)+'; path=/';</script>
三、HTML代码
test
<script>document.cookie='resolution='+Math.max(screen.width,screen.height)+'; path=/';</script>
Example in action
项目地址:http://adaptive-images.com/