Adaptive Images

By  on  

The landscape of web continues to change as we get more and more devices that we need to support. One concern when creating websites that should accommodate all screen sizes is image size. The acceptable size for an image is not the same across devices, so we usually end up compromising image size and quality on all devices; not the optimal solution, of course. Enter a solution called Adaptive Images, a PHP / .htaccess based solution for detecting screen size and delivering optimally sized images for the user's device.

Adaptive Images

Adaptive images provides an outstanding set of instructions for customizing the images generated by PHP's GD library, so you aren't stuck with rubbish images. Do yourself a favor and check out Adaptive Images -- it could be the perfect solution for your website imagery needs.

Recent Features

  • By
    Responsive Images: The Ultimate Guide

    Chances are that any Web designers using our Ghostlab browser testing app, which allows seamless testing across all devices simultaneously, will have worked with responsive design in some shape or form. And as today's websites and devices become ever more varied, a plethora of responsive images...

  • By
    JavaScript Promise API

    While synchronous code is easier to follow and debug, async is generally better for performance and flexibility. Why "hold up the show" when you can trigger numerous requests at once and then handle them when each is ready?  Promises are becoming a big part of the JavaScript world...

Incredible Demos

  • By
    Animated 3D Flipping Menu with CSS

    CSS animations aren't just for basic fades or sliding elements anymore -- CSS animations are capable of much more.  I've showed you how you can create an exploding logo (applied with JavaScript, but all animation is CSS), an animated Photo Stack, a sweet...

  • By
    HTML5 Input Types Alternative

    As you may know, HTML5 has introduced several new input types: number, date, color, range, etc. The question is: should you start using these controls or not? As much as I want to say "Yes", I think they are not yet ready for any real life...

Discussion

  1. This is the next BIG thing … I believe!

  2. jedi

    Will this method work with Joomla CMS sites?

    • It should — you’ll need to do your research about .htaccess though to make sure you don’t break Joomla.

  3. One thing I noticed with this… it says the page loads a tiny bit of JavaScript first and creates a cookie with window size. That cookie is not going to be able to be read until the second page load. So this idea won’t work for the first time a visitor sees your site. Am I wrong?

    • You’re wrong ;)

      If you include the script from an external file you’re right – because the time taken to fetch the external file is more than it takes to continue loading the HTML. But, if you have the code in the head (it’s only one line, and is more efficient embedded anyway), then the cookie actually gets set immediately, before the rest of the HTML has finished being loaded.

      Try it – go visit http://adaptive-images.com on a large screen. If you see large images it worked, because if there isn’t a cookie set it delivers the mobile resolution, which are much smaller.

  4. Here an alternative solution for adaptive images: http://litesite.org/holygrail/stage2/

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!